Nick Jonas
Nick Jonas

Reputation: 121

What is the difference between these two syntaxes

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

Answers (1)

Sanket Shah
Sanket Shah

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

Related Questions