use-context-selector: What should we do with the warning "Cannot update a component from inside the function body of a different component."

Currently, our Provider invokes subscribed components listeners so that they can force update. The reason why we need it is that we use the undocumented changedBits = 0 in Context API.

https://github.com/dai-shi/use-context-selector/blob/a43963373f123e380c9133eb6e1fc77a7fabc192/src/index.js#L9-L15

https://github.com/facebook/react/pull/17099 will warn this usage as it does not know about force update.

That’s fair. But, unless there’s another recommended way, we would need to keep our current approach.

Nobody will use this library if React shows the warning all the time. What should we do?

(Not only this library but also react-tracked and reactive-react-redux.)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 46 (30 by maintainers)

Most upvoted comments

Hmm, I’ll have to double-check for myself. The only other wat I’m aware of would be a custom event emitter. Much like a proxy but a bit more manual book keeping, I’m making a PoC off that since that would increase perf even further by calling every entry max. once.

That being said it should be concurrent since effects registered in P1 should be disposed on interrupt. I’ll check what the failing test is when I can open my laptop.

EDIT: I did this, https://github.com/JoviDeCroock/hooked-form/pull/61/files#diff-b863cdcf29e9f6f006d596a9ac293ed4 seems to work well in concurrent too perf seems to improve too since we can’t hit a callback twice anymore