I'm trying to use the map function to add a condition to display the email link.
If item contains email, display it.
However, it still does not work as it should showing "no link", console logs showing correct. I will be grateful for any help.
import React, { Component } from 'react';
import listIcon from '../img/list-icon.svg';
class FaqList extends Component {
state = {
items: [
{ id: 1, name: "Lorem.", answer: "Lorem ipsum dolor sit amet, consectetur adipisicing elit.", email: "[email protected]", expanded: false },
{ id: 2, name: "Lorem.", answer: "Lorem ipsum dolor sit amet, consectetur adipisicing elit.", expanded: false }
]
};
render() {
let link;
const isEmail = this.state.items.map(item => {
if (item.email) {
console.log(item.email); // showing email
link = 'show link';
} else {
link = 'no link';
}
});
return this.state.items.map(el => (
<div
key={el.id}
onClick={() => this.handleToggle(el.id)}
className={el.expanded ? "faq__columns--item--active faq__columns--item" : "faq__columns--item"}
>
<div className="faq__content">
<p className="mb-0">{el.answer}</p>
{link} // Template here
</div>
</div>
));
}
}
export default FaqList;
no link, if your last item is true, all items will returnshow link.. Not sure that's what your after.{link} // Template herewith{el.email ? <div>el.email</div> : null}.const isEmail =that's also going to not be very useful, it's just going to be an array ofundefined.