Reputation: 121
i have these two syntaxes these syntaxes are almost doing same thing but i am getting confused what is the differnce between these two,and which one is more suitable
<button onClick={() => dispatch(addTodo(todo))}>ADD</button>
<button onClick={dispatch(addTodo(todo))}>ADD</button>
Upvotes: 0
Views: 54
Reputation: 3091
<button onClick={() => dispatch(addTodo(todo))}>ADD</button>
will get dispatch the action when you click on Add
button.
<button onClick={dispatch(addTodo(todo))}>ADD</button>
will dispatch action when your component gets mounted
And you should avoid using <button onClick={dispatch(addTodo(todo))}>ADD</button>
Upvotes: 1