Hello everyone, I am stuck again.
I have a function that adds the html elements to an array, and then I want map the array on the next component with some of the information.
So my state looks like this: (with a bunch more elements)
<h5 class="ph2 ph0-ns pb3 link db">Service 1</h5>
<p id="This is wear you would describe what this item is." class="f5 f4-ns mb0 black-90">This is wear you would describe what this item is.</p>
and I am a little stumped on how I would map this. Has anyone done things like this before?
Thanks in advance for your help.
this.props.cart.map(c => {c.title} )
I’m not sure why this is throwing an error. Any help in this would be appreciated
Careful with your syntax.
map(c => {c.title} )
You have no return statement. You can miss out the return keyword if it’s a single expression, but you also miss out the curpy brackets if that’s the case. It’s difficult to tell exactly what you’re trying to do, but I assume you want:
map(c => c.title)
Which is the same as
map(function (c) {
return c.title
})
Or
map(c => {
return c.title
})
Hi, thanks for your reply!
Sorry I didn’t post my whole code. I have a return statement
class Cart extends Component {
state = {
cart: null
}
componentDidMount() {
console.log(this.props.cart)
}
render() {
if (this.props.cart.length !== 0)
return ( <div>
<ul>{
this.props.cart.map(c => {
<p> title: { c.id}</p>
}
)
}
</ul>
<button className="btn btn-success">CheckOut</button>
{
}
</div>
); else return (<h4 className="servicestitle">Add items to your cart and they will appear here.</h4>)
}
}
Do you still see anything wrong here? It’s giving me a “Expected an assignment or function call and instead saw an expression” error message.
Again, the syntax for your map callback function is incorrect, you aren’t returning a value.