question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What should we do with the warning "Cannot update a component from inside the function body of a different component."

See original GitHub issue

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.)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:46 (30 by maintainers)

github_iconTop GitHub Comments

1reaction
JoviDeCroockcommented, Oct 27, 2019

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

0reactions
dai-shicommented, Mar 7, 2020

I made a proper fix in react-tracked: https://github.com/dai-shi/react-tracked/pull/42 This is only possible because react-tracked has “update” function.

This is not possible with useContextSelector in userland, because update only happens in render. #13 is still a dirty workaround for now, until v2 lands (#12).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot update a component from inside the function body of a ...
If you call setState during a render on a different component, you will now see a warning: Warning: Cannot update a component from...
Read more >
too hard to fix "Cannot update a component from inside the ...
The problem is when one component queues an update in another component, while the first component is rendering. In other words, don't do...
Read more >
How to fix the "cannot update a component while rendering a ...
A quick guide to how I solved a confusing React error.
Read more >
Cannot update a component from inside the function body of a ...
JavaScript : React Warning : Cannot update a component from inside the function body of a different component [ Gift : Animated Search...
Read more >
How I fixed 'Cannot update a component from inside the ...
In this short article I'll highlight why Cannot update a component from inside the function body of a different component warning happened ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found