-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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 19] eslint-plugin-react-compiler
warning on destructured props mutation
#29093
Comments
The ESLint rule is designed to prevent mutation of props within a component, which can lead to unpredictable behavior and bugs. Even though destructuring props may create a new object, mutating the destructured props is still considered a bad practice in React.
|
Why is it bad practice? I assumed the problem was that a render function shouldn't mutate the props object because react wants to use it still after rendering, e.g. to allow rendering twice with the same properties. |
Thanks for filing this. You’re right that technically, destructuring props in this way will create a new object. However, this is only a shallow copy - so it’s okay to set a top-level property, but not for example to mutate the values of the properties. Our current model for mutability doesn’t support shallow copies, given how error prone they are. So for now we don’t expect to change the implementation here. Basically, it’s technically safe but error prone. We’ll consider if we can specialize the error message in this case. |
🤦 Oh ofcourse, it's about tracking mutations. Makes sense, thanks for explaining. |
…les are violated. check facebook/react#29093
Summary
Trying out
eslint-plugin-react-compiler
, it warns on the following code:Since
props
is destructured it's not mutating the original properties, so I believe this is a false positive.The text was updated successfully, but these errors were encountered: