import React, { Component } from 'react'
export default class DisplayTodo extends Component {
state = {
todo:["eat", "sleep", "repet"]
}
render() {
return (
<div>
{
this.state.todo.map((value)=>{
<p>{value}</p>
})
}
</div>
)
}
}
1) I know if i keep return in map it works but i want know why it failed
2)Moreover i referd to the link in for React
https://reactjs.org/docs/introducing-jsx.html#embedding-expressions-in-jsx
Now the error looks quit opposite to the explanition saying Expected an assignment or function call and instead saw an expression
3)in the react link explanation in above it is said You can put any valid JavaScript expression inside the curly braces
4) Moreover in javascript we can write like this why it is not possible in React
var a = [11,33,99]
a.map((val)=>{
console.log(val*2)
})
a.map((val)=>{ console.log(val*2) })
works is because your are executing theconsole.log
command for each iteration of the map function. You are not trying to return anything from aconsole.log
statement. This is different froma.map((val)=>{ return console.log(val*2) })
, which would return nothing (aconsole.log(x)
doesn't return anything). But when trying to render react components, you need to return them to the render function. - Seth Lutske