• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: React Redux – mapDispatchToProps called for every event in a map function

Resolved: React Redux – mapDispatchToProps called for every event in a map function

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Within my component I have a ‘OnClick’ handler that is supposed to fire a function called ‘onSelectProject’ within mapDispatchToProps that dispatches actions to the store. In this case it passes the id of the project passed from the click event
The problem I am having is that onSelectProject is firing for every project on a single click. If I have 10 projects the console.log within the function will show 10 times, one for every project.
index.js (ProjectComponent)
Why is onSelectProject being fired for every project on a single click?
I can provide more code if necessary or requested.

Answer:

make sure to pass function references not actual calls so your function is not called on every render but when you actually click the button:

If you have better answer, please add a comment about this, thank you!

mapdispatchtoprops mapstatetoprops react-redux reactjs
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to set consistent decimal separators in R data frame?

26/03/2023

Resolved: How to resolve LNK2001 in c++ projects

26/03/2023

Resolved: How to correctly initialize vector of number in Typescript

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.