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

[New] hook-use-state: add option to use useState hook with no value #3577

Closed
wants to merge 1 commit into from

Conversation

azat-io
Copy link

@azat-io azat-io commented May 14, 2023

This is useful if you want to forcibly re-render a component

@codecov
Copy link

codecov bot commented May 14, 2023

Codecov Report

Merging #3577 (01b8f81) into master (13f5c19) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #3577   +/-   ##
=======================================
  Coverage   97.62%   97.62%           
=======================================
  Files         132      132           
  Lines        9295     9298    +3     
  Branches     3400     3402    +2     
=======================================
+ Hits         9074     9077    +3     
  Misses        221      221           
Impacted Files Coverage Δ
lib/rules/hook-use-state.js 100.00% <100.00%> (ø)

@ljharb
Copy link
Member

ljharb commented May 14, 2023

This seems like a special enough case that it warrants an eslint override comment, and not a whole new option to the rule. What codebases would have more than one occurrence of this pattern?

@azat-io
Copy link
Author

azat-io commented May 14, 2023

I would suggest disabling error messages if no value is specified.

It doesn't sound like a naming problem:

const [, forceUpdate] = useState({})

@ljharb
Copy link
Member

ljharb commented May 14, 2023

This feels like an antipattern - components should never need to rerender unless props or state have changed.

@ljharb
Copy link
Member

ljharb commented Feb 19, 2024

Closing pending further discussion, since I'm not yet convinced this isn't an antipattern. I'd be happy to reopen if there's a reasonable use case where this option would be helpful.

@ljharb ljharb closed this Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants