Skip to content
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

[Bug]: hook-use-state suggested fix should update all reference #3810

Open
2 tasks done
axetroy opened this issue Aug 31, 2024 · 2 comments
Open
2 tasks done

[Bug]: hook-use-state suggested fix should update all reference #3810

axetroy opened this issue Aug 31, 2024 · 2 comments

Comments

@axetroy
Copy link

axetroy commented Aug 31, 2024

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

The current fix suggested is to simply replace the variable, This isn't smart enough

It should update all references

2024-08-31.16.48.48.mov

Expected Behavior

This is a custom react-hook-use-state rule I wrote. Before this, I didn’t know the existence of react/hook-use-state

it's smart enough

2024-08-31.16.49.50.mov

I have implemented almost all the functions of react/hook-use-state, but the logic is simpler

I checked the source code of hook-use-state, it is very complicated, and I can't modify it

I hope react/hook-use-state can also achieve this function by someone

eslint-plugin-react version

v7.35.0

eslint version

v9.9.1

node version

v20

@axetroy axetroy added the bug label Aug 31, 2024
@ljharb
Copy link
Member

ljharb commented Sep 8, 2024

If that can be done safely - including handling cases like { foo }, { foo: function () {} }, etc - that'd be a great enhancement.

@axetroy
Copy link
Author

axetroy commented Sep 8, 2024

If that can be done safely - including handling cases like { foo }, { foo: function () {} }, etc - that'd be a great enhancement.

@ljharb Yes, it's safely

## invalid(5): const [user, updateUser] = React.useState()\\nconst obj = { user, updateUser }

  > Input
  
        1 | const [user, updateUser] = React.useState()
        2 |
        3 | const obj = { user, updateUser }

  > Output
  
        1 | const [user, setUser] = React.useState()
        2 |
        3 | const obj = { user, updateUser: setUser }

  > Error 1/1: useState setter should be named "setUser"
  
      > 1 | const [user, updateUser] = React.useState()
          |              ^^^^^^^^^^
        2 |
        3 | const obj = { user, updateUser }

## invalid(6): const [user, updateUser] = React.useState()\\nexport { user, updateUser }

  > Input
  
        1 | const [user, updateUser] = React.useState()
        2 |
        3 | export { user, updateUser }

  > Output
  
        1 | const [user, setUser] = React.useState()
        2 |
        3 | export { user, setUser as updateUser }

  > Error 1/1: useState setter should be named "setUser"
  
      > 1 | const [user, updateUser] = React.useState()
          |              ^^^^^^^^^^
        2 |
        3 | export { user, updateUser }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants