Ask questionsFeedback on useEffect depndencies change error

Some feedback on useEffect

What is the current behavior?

I am using useEffect to load details on a set of users that are kept in props.

I want to minimize loading and there are situations where the array of users (and the actual user objects) are recreated but really they refer to the same identities.

So I do

const userIds = => id)
useEffect(() => {
  ...load more stuff by querying endpoints about these ids and set state..
}, userIds)

aand I run into a warning

The final argument passed to useEffect changed size between renders. The order and size of this array must remain constant

which to me is...kinda the point, is it not? I understand if we don't want to do a deep comparison in the dependencies, but if the dependencies themselves change...well that seems straightforward, run the effect.

I know that I can do [userIds.join(' ']) in this case, but that seems like just extra work for no reason and really anti-intuitive. And ends up doing the same exact thing but with extra steps!

To be clear, what I'm proposing is removing this whole block here and replacing it with

if (nextDeps.length !== prevDeps.length)
  return false

As far as I can tell, this warning serves no real purpose and makes the use case outlined above awkward to deal with


Answer questions togakangaroo

Yup - if you look at the code, it would seem that you can replace

    if (nextDeps.length !== prevDeps.length) {
        'The final argument passed to %s changed size between renders. The ' +
          'order and size of this array must remain constant.\n\n' +
          'Previous: %s\n' +
          'Incoming: %s',
        `[${prevDeps.join(', ')}]`,
        `[${nextDeps.join(', ')}]`,


if (nextDeps.length !== prevDeps.length)
  return false

and then my use case would be supported and there would be no other negative effects.

So I'm asking the team what is the purpose of this warning and also why not change it?


Related questions

Disable react strict mode on third party libraries hot 6
Warning: Unknown DOM property for. Did you mean htmlFor?
React@16.9 block `javascript:void(0);`
TypeError: Object(...) is not a function hot 4
Refs - "object is not extensible" hot 4
Warning: validateDOMNesting(...): <tr> cannot appear as a child of <table> hot 3
[ESLint] Feedback for 'exhaustive-deps' lint rule hot 3
React custom hook "Should have a queue. This is likely a bug in React" error message. hot 2
useEffect causes 'callback is not a function' exception hot 2
DevTools: Updating state or props in devtools does not trigger component update. hot 2
Infinite loop in useEffect using blank object or array hot 2
False-positive security precaution warning (`javascript:` URLs) hot 2
"DevTools v4 is incompatible with this version of React" with React Native & latest version of React hot 2
Hooks API - hook breaks when exported from module hot 2
Function components do not support contextType. hot 2
Github User Rank List