Hi All
I have an array with list of three Continents. I am mapping the array to a button using react map. When clicked on one button the rendering is happening for all three. Below is the code. I tried to use index but still no luck. I am assuming that the index was not placed in right position. can someone help me with the below please.
Here in Overlay I mentioned a condition to check if it is NA or not. Even if I click on a different button which is not NA then also all the three are getting rendered.
Array:
const locationList = [
{
id:"L1",
code:"NA",
type:"location",
title:"North America",
},
{
id:"L2",
code:"AS",
type:"location",
title:"Asia",
},
{
id:"L3",
code:"EU",
type:"location",
title:"Europe",
}
];
export default locationList;
Main Function:
import { locationList } from './Data/FooterLinkList';
import { Overlay } from './CustomHooks/Overlay';
import { useState } from 'react';
function Footer() {
const [isOverlayOpen, setisOverlayOpen] = useState(false);
return (
<section className="footer">
<div id="footerSections">
<div className="footerLocation">
<div className='footerHeads'>
<h5>Locations</h5><br />
</div>
{locationList.map((location) => (
<ul key={location.id}>
<li className='footerList'>
<button key={location.id} className='footerLinks' id="locationLinkBtn" type="button" onClick={() => setisOverlayOpen(!isOverlayOpen)}>{location.title}</button>
<Overlay isOpen={isOverlayOpen} onClose={() => setisOverlayOpen(!isOverlayOpen)} type={location.type} props={location.code}></Overlay>
</li>
</ul>
))}
</div>
</div>
<p>2024 • ©Lakshmi Shashank Ch</p>
</section>
);
}
export default Footer;
Overlay hook:
const overlayFunc = (code,value) =>{
console.log(code);
console.log(value);
console.log("inside overlayFunc");
if(code === 'location' && value==='NA'){
return(
<>
"Hello Shashank"
</>
);}
}
export const Overlay = ({isOpen,onClose,type,props}) => {
console.log(type);
return (
<>
{isOpen ? (
<div className="overlay">
<div className="overlay_bg" onClick={onClose} />
<div className="overlay_container">
<div className="overlay_controls">
<button className="overlay_btn" type="button" onClick={onClose}>
</button>
</div>
<div>
{
isOpen?(overlayFunc(type,props)):null
}
</div>
</div>
</div>
) : null}
</>
)
}
export default Overlay;