ianstormtaylor / react-values

A set of tiny React components for handling state with render props.
https://git.io/react-values
MIT License
1.02k stars 39 forks source link

Can't call setState (or forceUpdate) on an unmounted component #22

Closed cdock1029 closed 6 years ago

cdock1029 commented 6 years ago

Using <BooleanValue> to control whether a modal is open, which holds a form to update data rendered in a table rows with react-table. Default rows render with an expander closed, so the BooleanValue isn't rendered.. until the row is expanded.

After an async data update, my parent component re-renders the table..

I'm generically closing the modal with set(false) whether the modal was closed simply with a Cancel, or an actual re-rendering data update.

On re-render the <BooleanValue> is not rendered since row is not expanded.

Of course that generates this error:

Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
    in BooleanValue

Is this something that should be handled internally within this library? Then we don't have to worry about tracking mounted state or rewrite separate logic for different toggling use cases...

If component is gone, then these mutate operations could be no-ops...