aweary / aweary/react-copy-write

Make updateState available in constructor instead of componentDidMount

Open
#56 6 comments 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.8k
Forks
54
PR merge metrics
No merged PRs in 30d

Description

Hey there. We recently started using react-copy-write in a small application and had a great experience so far, but there is still something that interferes with our application flow, which is the inability to call `mutate` before a provider is fully mounted.

https://codesandbox.io/s/oowloz2qk9

In this example the app will crash, because `mutate` is called before the surrounding provider is fully mounted. We want our ApiProvider to be wrapped around the whole app while still being able to use life cycle hooks to do initialization work that could mutate the state this provider gives us.

What we did for experimental reasons is to move the `componentDidMount` code from `CopyOnWriteStoreProvider` to a constructor and everything worked fine afterwards. So my question is whether it's possible to do this switch or if there are special reasons for the design decision to make `updateState` only available after `componentDidMount` of `CopyOnWriteStoreProvider` ran? Are there any performance implications or other pitfalls we are overlooking? If not I'd be glad to open a PR for this issue.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.