Answer the question
In order to leave comments, you need to log in
How to change array element on click?
There is an array with photos, which is rendered using map:
<div className="about-pictures-container">
{ images.map(image => {
return (
<ImageCard
key = {person.id}
name = {eng ? person.nameENG : person.nameRU}
image = {person.img}
bio = {eng ? person.bioENG : person.bioRU}
/>
)
}) }
</div>
<div className="image-card">
<div className="card-image-info-container">
<img className={"bio-img " + (showBio ? "invisible" : null)} src={image} onClick={toggleBio} />
<div className={"bio-text-container " + (showBio ? "bio-visible" : null)}>
<p className="card-bio"> {bio} </p>
<button className="btn bio-btn" onClick={() => toggleBio(id)}>Close</button>
</div>
</div>
<p className="image-card-name"> {name} </p>
</div>
toggleBio = id => {
this.setState({
showBio: ! this.state.showBio
})
}
Answer the question
In order to leave comments, you need to log in
You can simply change the state of the card:
const ImageCard = ({ image, bio }) => {
const [showBio, setShowBio] = useState(false);
const handler = useCallback(() => {
setShowBio(state => !state);
}, []);
return (
<Wrapper>
{showBio ? <Bio bio={bio} /> : <Image src={image} />}
<Button onClick={hanlder}>Show bio</Button>;
</Wrapper>
);
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question