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

[eslint-plugin-react-hooks] Report constant constructions #19590

Merged
merged 9 commits into from
Aug 13, 2020

Commits on Aug 11, 2020

  1. [eslint-plugin-react-cooks] Report constant constructions

    The dependency array passed to a React hook can be thought of as a list of cache keys. On each render, if any dependency is not `===` its previous value, the hook will be rerun. Constructing a new object/array/function/etc directly within your render function means that the value will be referentially unique on each render. If you then use that value as a hook dependency, that hook will get a "cache miss" on every render, making the dependency array useless.
    
    This can be especially dangerous since it can cascade. If a hook such as `useMemo` is rerun on each render, not only are we bypassing the option to avoid potentially expensive work, but the value _returned_ by `useMemo` may end up being referentially unique on each render causing other downstream hooks or memoized components to become deoptimized.
    captbaritone committed Aug 11, 2020
    Configuration menu
    Copy the full SHA
    bc36370 View commit details
    Browse the repository at this point in the history

Commits on Aug 12, 2020

  1. Configuration menu
    Copy the full SHA
    450cdfd View commit details
    Browse the repository at this point in the history
  2. Don't give an autofix of wrapping object declarations

    It may not be safe to just wrap the declaration of an object, since the object may get mutated.
    
    Only offer this autofix for functions which are unlikely to get mutated.
    
    Also, update the message to clarify that the entire construction of the value should get wrapped.
    captbaritone committed Aug 12, 2020
    Configuration menu
    Copy the full SHA
    75fcb35 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    4b6e20e View commit details
    Browse the repository at this point in the history

Commits on Aug 13, 2020

  1. Configuration menu
    Copy the full SHA
    e0ca072 View commit details
    Browse the repository at this point in the history
  2. Trim trailing whitespace

    captbaritone committed Aug 13, 2020
    Configuration menu
    Copy the full SHA
    4dc35db View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    eaa2aff View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    2b7ae4b View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    31f75cd View commit details
    Browse the repository at this point in the history