-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Which is better to use three definitions of variables in React ES6? Why? #11839
Comments
hi, all can do what you need, it just depends on what you want to do in the end. in particular your method Two stores the array in state so setting that state will trigger a rerender, whereas the other two methods you gave will involve mutating the array without rerendering the component. This is more of a question of opinion/code style and so is not a suitable issue to raise in this github repo. please have a look at https://reactjs.org/community/support.html for more appropriate venues of community support. thanks! |
Agree with @sw-yx. My 2 cents: Option 1: Doesn't allow mutation. Go with this if you want to enforce this. Option 2: Allows mutation, triggers re-rendering on mutation. Option 3: Allows mutation, no re-rendering on mutation. For your specific use case, Option 1 is the best choice. |
which is the best way to use the three defined methods?
The arr does not need to be rendered, just make a temporary cache comparison new data use!
Thanks!
The text was updated successfully, but these errors were encountered: