My code is working, I've been trying to figure out how to set the IonCol side to side instead of stack, it is responsive but the columns don't move, they stretch, any ideas how I could fix this?
const Home: React.FC = () => {
return (
<IonPage>
<IonHeader translucent={true}>
<IonToolbar color="danger">
<IonTitle>Portfolio</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent fullscreen>
<div id="container">
<IonGrid>
<IonRow>
<IonCol size-xs="12" size-md="4">
<img src="https://images.unsplash.com/photo-1425421669292-0c3da3b8f529?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1469&q=80" />
</IonCol>
<IonCol size-xs="12" size-md="8">
<div>
<h1>Batman</h1>
<h5>
<strong>The Knight</strong>
</h5>
</div>
</IonCol>
</IonRow>
</IonGrid>
<IonGrid>
<IonRow>
<IonCol size-xs="12" size-md="12">
<h2>About</h2>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
Deleniti facilis at nostrum modi ex aspernatur reiciendis
repellat? A beatae quo fugit est perferendis nobis optio
aliquid rem et blanditiis qui, asperiores molestias iste earum
neque consequatur placeat accusantium quos! Deserunt corrupti
vel minima asperiores. Quo molestias inventore sapiente
recusandae aliquam?
</p>
</IonCol>
</IonRow>
</IonGrid>
<div id="container">
<IonGrid>
<IonRow>
<IonCol size='8'>
<h1>Work Experience</h1>
</IonCol>
<IonCol size="8">
<IonAccordionGroup>
<IonAccordion value="first">
<IonItem slot="header" color="light">
<IonLabel>Head of technology, Avengers</IonLabel>
</IonItem>
<div className="ion-padding" slot="content">
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing
elit. Harum, quod!
</p>
</div>
</IonAccordion>
<IonAccordion value="second">
<IonItem slot="header" color="light">
<IonLabel>CEO, Stark Industries</IonLabel>
</IonItem>
<div className="ion-padding" slot="content">
Lorem, ipsum dolor sit amet consectetur adipisicing elit.
Sit eveniet libero doloribus!
</div>
</IonAccordion>
<IonAccordion value="third">
<IonItem slot="header" color="light">
<IonLabel>CFO, IBM</IonLabel>
</IonItem>
<div className="ion-padding" slot="content">
Lorem ipsum dolor, sit amet consectetur adipisicing elit.
Fugiat nesciunt voluptatibus saepe provident.
</div>
</IonAccordion>
</IonAccordionGroup>
</IonCol>
</IonRow>
</IonGrid>
</div>
<div id="container">
<IonGrid>
<IonRow>
<IonCol size="12">
<IonList>
<IonItem>
<h2>Technical Experience</h2>
</IonItem>
<IonGrid>
<IonRow>
<IonCol size='12'>
<IonItem>
<IonList>
<IonLabel>Java</IonLabel>
</IonList>
</IonItem>
</IonCol>
</IonRow>
</IonGrid>
<IonItem>
<IonLabel>Javascript</IonLabel>
</IonItem>
<IonItem>
<IonLabel>React</IonLabel>
</IonItem>
<IonItem>
<IonLabel>NodeJs</IonLabel>
</IonItem>
<IonItem>
<IonLabel>Python</IonLabel>
</IonItem>
</IonList>
</IonCol>
</IonRow>
</IonGrid>
</div>
</div>
<IonFooter>
<IonToolbar>
<IonButton expand="full">
Tel. 123-456-88888 | Knight#batman.com
</IonButton>
</IonToolbar>
</IonFooter>
</IonContent>
</IonPage>
);
};
export default Home;
I tried setting different size-xs='4', size-md='8', just size='4' and size='8', putting it under the IonGrid but no success.
The column that says Work experience and its elements needs to be next to technical experience once the windows maximizes... responsive...
You are having them in different grids, they would align vertically. if you want some IonCols to stand horizontally, they should be in the same IonGrid and their combined size should be less than 12, otherwise it would go to next line because the size system divide a row into 12 units. something like this:
<IonGrid>
<IonRow>
<IonCol>
<h1>Work Experience</h1>
</IonCol>
<IonCol>
<IonList>
<IonItem>
<h2>Technical Experience</h2>
</IonItem>
...
</IonList>
</IonCol>
</IonRow>
</IonGrid>
Also size is not an attribute of IonGrid, it is for IonCol. if you want your grid's width to be limited, you should fix it in css and probably use css grid or flexbox etc.
Related
I'm stuck. So what do I want from my app:
to animate sections with left fading and opacity (0 to 1) when I scroll down or up.
reuse this component later with different separate components.
What I have now:
Js function that perfectly works with simple HTML and CSS.
nothing from my 'want list'
Please help!
My code is next:
import React from 'react';
const TestAnimation = () => {
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('.opacity-100');
} else {
entry.target.classList.remove('.opacity-100');
}
});
});
const hiddenElements = document.querySelectorAll('.opacity-0');
hiddenElements.forEach((el) => {
observer.observe(el);
});
return (
<div className='m-0 bg-slate-900 p-0 text-white'>
<section className='grid min-h-screen place-items-center content-center opacity-0'>
<h1>Test</h1>
</section>
<section className='grid min-h-screen place-items-center content-center opacity-0'>
<h2>This is first page</h2>
<p>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Autem modi voluptatem est iste a commodi
nesciunt saepe quisquam id dignissimos odit, repellat asperiores laboriosam quibusdam expedita
itaque blanditiis eos pariatur.
</p>
</section>
<section className='grid min-h-screen place-items-center content-center opacity-0'>
<h2>This is third page</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur veniam sint illo quas beatae,
eum omnis, deleniti error, eveniet praesentium fugiat quia quod? Maxime, placeat reiciendis ab
debitis exercitationem nemo. Laborum perspiciatis eum architecto laboriosam, necessitatibus
voluptatibus cupiditate accusantium corrupti placeat mollitia omnis tenetur! Incidunt fugiat
possimus quod, quidem itaque ducimus, perspiciatis eligendi, commodi voluptate cupiditate nihil
corrupti soluta maxime.
</p>
</section>
<section className='grid min-h-screen place-items-center content-center opacity-0'>
<h2>this is Fourth page</h2>
<p className='text-center'>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos similique harum, officiis facere odit
adipisci maxime obcaecati placeat, quibusdam totam magni eaque? Dicta id commodi saepe dignissimos
quam unde eaque.
</p>
</section>
</div>
);
};
export default TestAnimation;
You should move the initiation of the intersection observer into a useEffect hook.
Here is an example of an Observer component I've used in the past:
export default function Observer({ children, sectionRef, callback }) {
function onObserver(entries) {
const entry = entries[0];
console.log(entry);
if (entry.isIntersecting) {
callback(sectionRef.current.id);
console.log("element in:", entry.target.id);
} else {
console.log("element left:", entry.target.id);
}
}
useEffect(() => {
const refCopy = sectionRef;
let options = {
root: null,
rootMargin: "0% 0% -5% 0%",
threshold: [0.5],
};
let observer = new IntersectionObserver(onObserver, options);
if (refCopy.current) {
observer.observe(refCopy.current);
}
return () => {
if (refCopy.current) {
observer.unobserve(refCopy.current);
}
};
}, [sectionRef]);
return <div id="observation">{children}</div>;
}
And here is how to use it:
export default function Education({ children, handleInView }) {
const sectionRef = useRef(null);
return (
<Observer sectionRef={sectionRef} callback={handleInView}>
<section
ref={sectionRef}
id="education"
className="education"
data-scroll-section
data-scroll
data-scroll-class="purpleColor"
>
<Pencils />
<div className="details">
<div className="side-by-side">
<div className="title" data-scroll data-scroll-speed={2}>
<span>Fullstack</span>
<span> Software </span>
<span>Engineer</span>
</div>
</div>
</div>
</section>
</Observer>
);
}
I'm currently trying to fetch some data in my Next.js project using the getStaticProps() function and I continue to get this error:
TypeError: Cannot read property 'map' of undefined
My code looks like this:
export const getStaticProps = async () => {
const data = [
{
"id": 1,
"question": "Lorem ipsum dolor sit amet consectetur adipisicing elit.",
"answer": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Iste magni at magnam placeat. Non, saepe?"
},
{
"id": 2,
"question": "Lorem ipsum dolor sit amet consectetur adipisicing elit.",
"answer": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Iste magni at magnam placeat. Non, saepe?"
}
]
return {
props: {
questions: data
}
}
}
export default function FAQ({ questions }) {
return (
<div className="p-8 grid bg-blanco" >
<div className="grid place-content-center text-center mt-10 md:mt-0" >
<h1 className="text-2xl text-gun-rose-700 font-bold" >¿Tiene preguntas? Mira aquí</h1>
<h3 className="text-gun-rose-300 mt-4 max-w-2xl" >Lorem ipsum dolor sit amet consectetur adipisicing elit. Sunt, suscipit. Aliquid molestias eveniet ullam? Dolores, minus? Perspiciatis neque voluptates iste!</h3>
</div>
{questions.map(q => (
<div className="" key={q.id}>
<h3 className="">{q.question}</h3>
<p className="">{q.answer}</p>
</div>
))}
</div>
)
}
Any guidence will be appreciated, thanks in advance :)
It could be an async issue where questions is not immediately available. Try with a null check at the start of questions.
export default function FAQ({ questions }) {
return (
<div className="p-8 grid bg-blanco" >
<div className="grid place-content-center text-center mt-10 md:mt-0" >
<h1 className="text-2xl text-gun-rose-700 font-bold" >¿Tiene preguntas? Mira aquí</h1>
<h3 className="text-gun-rose-300 mt-4 max-w-2xl" >Lorem ipsum dolor sit amet consectetur adipisicing elit. Sunt, suscipit. Aliquid molestias eveniet ullam? Dolores, minus? Perspiciatis neque voluptates iste!</h3>
</div>
{questions && questions.map(q => (
<div className="" key={q.id}>
<h3 className="">{q.question}</h3>
<p className="">{q.answer}</p>
</div>
))}
</div>
)
}
Edit 1:
The getStaticProps method can only be used on the top level component of a page as stated in the caveats
The fix is to move the getStaticProps method to the top level page component. I've demo'ed this in a sandbox as folder structures are so important, link here.
<ClickAwayListener onClickAway={this.handleClose}>
<Navbar color="light" light expand="md" className="navbar-fixed-top">
<Container>
<Nav className="ml-auto" navbar>
<NavItem>
<NavLink href="#" id="link-menu-1" className="nav-link" onClick={this.handleLoans}>LOANS {this.state.LOANS ? <FontAwesomeIcon className="faChevronDown" icon={faChevronUp} /> : <FontAwesomeIcon className="faChevronDown" icon={faChevronDown} />} </NavLink>
</NavItem>
<NavItem>
<NavLink href="#" id="link-menu-2" className="nav-link" caret onClick={this.handleGovtSubsidy}>Govt. Subsidy {this.state.GovtSubsidy ? <FontAwesomeIcon className="faChevronDown" icon={faChevronUp} /> : <FontAwesomeIcon className="faChevronDown" icon={faChevronDown} />} </NavLink>
</NavItem>
<NavItem>
<NavLink href="#" id="link-menu-3" className="nav-link" caret onClick={this.handleGENINSURANCE}> GEN. INSURANCE {this.state.GENINSURANCE ? <FontAwesomeIcon className="faChevronDown" icon={faChevronUp} /> : <FontAwesomeIcon className="faChevronDown" icon={faChevronDown} />} </NavLink>
</NavItem>
<NavItem>
<NavLink href="#" id="link-menu-4" className="nav-link" caret onClick={this.handleLIFEINSURANCE}>LIFE INSURANCE {this.state.LIFEINSURANCE ? <FontAwesomeIcon className="faChevronDown" icon={faChevronUp} /> : <FontAwesomeIcon className="faChevronDown" icon={faChevronDown} />} </NavLink>
</NavItem>
<NavItem>
<NavLink href="#" id="link-menu-5" className="nav-link" caret onClick={this.handleELITESERVICES}>ELITE SERVICES {this.state.ELITESERVICES ? <FontAwesomeIcon className="faChevronDown" icon={faChevronUp} /> : <FontAwesomeIcon className="faChevronDown" icon={faChevronDown} />} </NavLink>
</NavItem>
</Nav>
</Container>
</Navbar>
</ClickAwayListener>
<div className="submenu-cover">
{this.state.LOANS ?
<div id="menu-1" className="header-submenu loan-submenu">
<PerfectScrollbar component="div" >
<Container fluid={true} >
<Row xs="4" >
<Col className="img-cover">
<img src={LoanMenu} />
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Retails Loans</div>
<ListGroup>
<ListGroupItem onClick={() => this.gotoPersonalLoanForm()}>Retail Home Loan</ListGroupItem>
<ListGroupItem>Retail LAP (Loan Against Property)</ListGroupItem>
<ListGroupItem>Retail LRD (Lease Rental Discounting)</ListGroupItem>
<ListGroupItem>Retail APF</ListGroupItem>
</ListGroup>
</div>
<div className="list-wrap">
<div className="list-title">INFRA Loans</div>
<ListGroup>
<ListGroupItem>Construction Finance</ListGroupItem>
<ListGroupItem>Infrastructure Finance</ListGroupItem>
</ListGroup>
</div>
</Col>
<Col>
<div className="list-wrap">
<div className="list-title">SME Loans</div>
<ListGroup>
<ListGroupItem><Link to='/BusinessLoanForm'>SME CC/OD</Link></ListGroupItem>
<ListGroupItem>SME Term Loan</ListGroupItem>
<ListGroupItem>SME Term Loan + CC/OD</ListGroupItem>
<ListGroupItem>SME NFB (Non Fund Base)</ListGroupItem>
<ListGroupItem>SME LAP (Loan Against Property)</ListGroupItem>
<ListGroupItem>SME CGTMSE</ListGroupItem>
</ListGroup>
</div>
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Unsecured Loans</div>
<ListGroup>
<ListGroupItem>Business Loan</ListGroupItem>
<ListGroupItem>Personal Loan</ListGroupItem>
<ListGroupItem>School Fee Funding</ListGroupItem>
</ListGroup>
</div>
<div className="list-wrap">
<div className="list-title">Channel Finance</div>
<ListGroup>
<ListGroupItem>Anchor Lead Bill Discounting</ListGroupItem>
<ListGroupItem>Anchor Lead Input Finance</ListGroupItem>
<ListGroupItem>Vendor Lead Bill Discounting</ListGroupItem>
</ListGroup>
</div>
</Col>
</Row>
</Container>
</PerfectScrollbar>
</div>
: ''}
{this.state.GovtSubsidy ?
<div id="menu-2" className="header-submenu subsidy-submenu">
<PerfectScrollbar component="div" >
<Container fluid={true} >
<Row xs="4" >
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Interest Subsidy</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap">
<div className="list-title">Central Govt. Subsidy</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Capital Subsidy</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap">
<div className="list-title">Electric Subsidy</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">GST Subsidy</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap">
<div className="list-title">Others</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col className="img-cover">
<img src={SubsidyMenu} />
</Col>
</Row>
</Container>
</PerfectScrollbar>
</div>
: ''}
{this.state.GENINSURANCE ?
<div id="menu-3" className="header-submenu geninsurance-submenu">
<PerfectScrollbar component="div" >
<Container fluid={true} >
<Row xs="4" >
<Col className="img-cover">
<img src={GenInsuranceMenu} />
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Aviation Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Credit Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Agriculture Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap">
<div className="list-title">Motor Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Engineering Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Fire Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap">
<div className="list-title">Health Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Liability Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Marine Cargo</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
<div className="list-wrap">
<div className="list-title">Miscellaneous Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
</Row>
</Container>
</PerfectScrollbar>
</div>
: ''}
{this.state.LIFEINSURANCE ?
<div id="menu-4" className="header-submenu lifeinsurance-submenu">
<PerfectScrollbar component="div" >
<Container fluid={true} >
<Row xs="4" >
<Col>
<div className="list-wrap">
<div className="list-title">Term Plan Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col>
<div className="list-wrap">
<div className="list-title">Traditional Plan Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col>
<div className="list-wrap">
<div className="list-title">ULIP Plan Insurance</div>
<div className="list-text">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
<Col className="img-cover">
<img src={LifeInsuranceMenu} />
</Col>
</Row>
</Container>
</PerfectScrollbar>
</div>
: ''}
{this.state.ELITESERVICES ?
<div id="menu-5" className="header-submenu eliteservices-submenu">
<PerfectScrollbar component="div" >
<Container fluid={true} >
<Row xs="4" >
<Col className="img-cover">
<img src={EliteServicesMenu} />
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Business Valuations</div>
<ListGroup>
<ListGroupItem>Business Takeover</ListGroupItem>
<ListGroupItem>Purchase Valuation</ListGroupItem>
<ListGroupItem>New Share Issue valuation </ListGroupItem>
<ListGroupItem>Business Synergy Valuation </ListGroupItem>
</ListGroup>
</div>
<div className="list-wrap">
<div className="list-title">Strategic Financial Advisor</div>
<ListGroup>
<ListGroupItem>Company profile preparation</ListGroupItem>
<ListGroupItem>Outsourced CFO Service</ListGroupItem>
<ListGroupItem>Project Report</ListGroupItem>
<ListGroupItem>Financial Projections</ListGroupItem>
</ListGroup>
</div>
</Col>
<Col>
<div className="list-wrap">
<div className="list-title">Compliance Services</div>
<ListGroup>
<ListGroupItem>COP certificate</ListGroupItem>
<ListGroupItem>MOF certificate</ListGroupItem>
<ListGroupItem>Funds Utilisation Certificate</ListGroupItem>
<ListGroupItem>DCCO Certificate </ListGroupItem>
<ListGroupItem>Net Worth Certificate </ListGroupItem>
<ListGroupItem>Statutory Compliance Certificate </ListGroupItem>
<ListGroupItem>Certificate for Subsidy</ListGroupItem>
<ListGroupItem>Stock Statement </ListGroupItem>
</ListGroup>
</div>
</Col>
<Col>
<div className="list-wrap list-wrap-mb">
<div className="list-title">Equity Fund Raise</div>
<ListGroup>
<ListGroupItem>Angle Fund Raise</ListGroupItem>
<ListGroupItem>Seed Fund Raise</ListGroupItem>
<ListGroupItem>VC Fund Raise </ListGroupItem>
<ListGroupItem>PE Fund Raise</ListGroupItem>
</ListGroup>
</div>
<div className="list-wrap">
<div className="list-title">Merger & Acquisition</div>
<div className="list-text set-max">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
</div>
<div className="know-more">Know More</div>
</div>
</Col>
</Row>
</Container>
</PerfectScrollbar>
</div>
: ""}
</div>
this is my code and I have already applied the ClickAwayListener but it's not working and I'm not able to solve this error because I'm unable to understand the bug debugger I have applied in so many ways but still couldn't get any success. Thank you so much in advance for helping me.
In this code, the listing of the header menu is in Navbar and when we click on a particular header menu the submenu of that menu will open.
And when I click away from that menu the submenu section will be closed.
just because of a lack of experience in Reactjs I'm unable to solve it.
It'll be great for me if anyone can give me the solution to this.
Im creating a project that needs to have variable styles and images dependent on the route its in so that i dont have to recreate components.
I've successfully gotten images and text in in the code below. but i am unsuccessful in getting the string value for className in the first div into the css.
Please help!
import React, { Fragment, useEffect } from "react";
import { useLocation } from "react-router-dom";
import homeimg from "../../images/homeimg.jpg";
import consimg from "../../images/consimg.jpg";
import solsimg from "../../images/solsimg.jpg";
const Hero = () => {
useEffect(() => {}, []);
const location = useLocation();
const { pathname } = location;
let img = null;
if (pathname === "/") {
img = homeimg;
} else if (pathname === "/consultants") {
img = consimg;
} else if (pathname === "/solutions") {
img = solsimg;
}
return (
<Fragment>
<div
className={
{pathname === "/" && ("grid-home")}
{pathname === "/consultants" && ("grid-consultants")}
{pathname === "/solutions" && ("grid-solutions")}
}>
<div className='overlay'>
<div>
<p className='bg-dark'></p>
<img src={img} alt='' />
</div>
</div>
<div className='copy'>
{pathname === "/" && (
<div>
<h1 className='text-primary'>Snorem Snipsem</h1>
<h3 className='text-danger'>Lorem ipsum dolor sit.</h3>
<p className='text-light'>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br />
Repellat nemo, in odit culpa, illo earum voluptatum
<br />
aliquam quaerat iure sunt, quos similique quod <br />
Recusandae voluptates voluptatum nisi sint dicta.
</p>
</div>
)}
{pathname === "/consultants" && (
<div>
<h1 className='text-primary'>Lorem, ipsum.</h1>
<h3 className='text-danger'>Lorem ipsum dolor sit.</h3>
<p className='text-light'>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br />
Repellat nemo, in odit culpa, illo earum voluptatum
<br />
aliquam quaerat iure sunt, quos similique quod <br />
Recusandae voluptates voluptatum nisi sint dicta.
</p>
</div>
)}
{pathname === "/solutions" && (
<div>
<h1 className='text-primary'>Forem, ipsum.</h1>
<h3 className='text-danger'>Lorem ipsum dolor sit.</h3>
<p className='text-light'>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br />
Repellat nemo, in odit culpa, illo earum voluptatum
<br />
aliquam quaerat iure sunt, quos similique quod <br />
Recusandae voluptates voluptatum nisi sint dicta.
</p>
</div>
)}
</div>
</Fragment>
);
};
export default Hero;
At first declare it and try to use
let cn = "";
if(pathname === '/'){
cn = grid-home
}
....
return(
<div className={cn}>
..
..
You may use classnames library in order to add dynamically classnames https://www.npmjs.com/package/classnames
const divClass = classNames({
'grid-home': pathname === "/" ,
'grid-consultants': pathname === "/consultants",
'grid-solutions': pathname === "/solutions"
});
<div className={divClass}>
in my code .col-md-3 is not getting loaded for all rows.
<div class="row">
<div class="col-md-3 col-md-offset-2 footer-image col-sm-3 col-sm-offset-2 col-xs-2 col-xs-offset-3">
<img alt="Get Started" src="/assets/f_1.png" alt="Life Style" title="life style"
class="img-thumbnail resize-image"/>
</div>
<div class="col-md-3 footer-image col-sm-3 col-xs-2">
<img alt="Get Started" src="/assets/f_1.png" alt="About Us" title="About Us"
class="img-thumbnail resize-image" />
</div>
<div class="col-md-3 footer-image col-sm-3 col-xs-2">
<img alt="Get Started" src="/assets/f_1.png" alt="Contact Us" title="Contact Us"
class="img-thumbnail resize-image" />
</div>
</div>
<div class="row">
<div class='col-md-3'>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae, in, soluta deserunt
</div>
<div class='col-md-3'>
Delectus, earum, nobis, esse expedita corporis eaque cupiditate nihil quia consequuntur ea
</div>
<div class='col-md-3'>
Delectus, quam, minus quisquam fugit harum a ab quo fugiat obcaecati molestias voluptatem velit
</div>
</div>
In the first row section, where I am adding images, there the col-md-3 is getting loaded, but the same is not getting loaded in next row(with text contents) !
is this what you're trying to achieve? Try reconstructing your .cols again without the offsets.
<div class="row">
<div class="col-md-3"><img src="http://placehold.it/350x150"></div>
<div class="col-md-3"><img src="http://placehold.it/350x150"></div>
<div class="col-md-3"><img src="http://placehold.it/350x150"></div>
<div class="col-md-3"><img src="http://placehold.it/350x150"></div>
</div>
<div class="row">
<div class="col-md-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aspernatur, tempore, blanditiis ab consequuntur ea molestiae?</div>
<div class="col-md-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui, quis libero cupiditate repellat iusto voluptatum.</div>
<div class="col-md-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatibus, assumenda, aspernatur nihil ut quia eveniet!</div>
<div class="col-md-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatibus, assumenda, aspernatur nihil ut quia eveniet!</div>
</div>