drcmda / immer-wieder

✨ React 16 context wrap with redux semantics powered by immer
MIT License
166 stars 9 forks source link

Child components can't setState in `componentDidMount` #4

Closed giannif closed 5 years ago

giannif commented 5 years ago

A child component wrapped with hoc can't invoke setState in componentDidMount because this.mounted is false.

I have a codesandbox demonstrating this, an action is invoked in componentDidMount, but the setState will not execute. https://codesandbox.io/s/9zonjjq3k4

If you have any ideas, I'm up for doing a pr. I'm not exactly sure why the this.mounted check is required

Great lib though :)

drcmda commented 5 years ago

well it is supposed to guard against async setState firing on a dead/unmounted component. It looks like the hoc wants to setState before the inner component is mounted? PRs welcome of course!

giannif commented 5 years ago

@drcmda created a PR for this, setting an unmounted flag instead of a mounted flag, which isn't required for setState. I've done unmounted to avoid setState errors a few times before

giannif commented 5 years ago

@drcmda working wonderfully after the patch, thanks!