This is my working react component. Here I have two functions getStyle and markComplete. What is the reason for getStyle
to be called with brackets '()' like getStyle()
and markComplete
to be called without them?
function TodoItem(props) {
const getStyle = () => {
return {
backgroundColor: '#f4f4f4',
padding: '10px',
border: '1px #ccc dotted',
textDecoration: props.todo.completed ? 'line-through' : 'none'
}
}
const markComplete = (e) => {
console.log(props.todo)
}
return (
<div style={getStyle()}>
<p>
<input type="checkbox" onChange={markComplete} /> { }
{props.todo.title}
</p>
</div>
)
}