-
Notifications
You must be signed in to change notification settings - Fork 45.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React memo always get the same results on prevparams and next params #16643
Comments
So, this line makes a shallow copy of the array taskList: const arrTemp=[...prevState.taskList]; This means that while the array instances are different, the actual items are still shared among the 2 arrays. Then, this line: arrTemp[position].stateCheckbox=!arrTemp[position].stateCheckbox; mutates the value of the item. As mentioned, because it's shared, it will change the value in both the arrays. Hence, the failure to detect the change in the A quick attempt at a workaround: const arrTemp=[...prevState.taskList];
arrTemp.splice(position, 1, {...arrTemp[position], stateCheckbox: !arrTemp[position].stateCheckbox ) I haven't tested it, but note how it creates a whole new item to replace the item that's being changed. This is more of a usage question, consider using one of community resources in the future https://reactjs.org/community/support.html |
thanks for your help, it works! |
the same problem, please help me. this function call in parent. this is my child component |
Hello i'm trying to implement React memo on my project to especify when i want to update my component. But i realize that i'm always receiving the same values on prevProps, and currentProps so i cant make any validation.
Now im making it in this way:
The field I'm editing it's in the parent component and it made it in this way :
it works well and update the field on it's specify position. My problem its that on React memo it cant detect the previous state.
Can anybody give me some ideas about what am i making wrong..
thanks..
The text was updated successfully, but these errors were encountered: