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.

Make updateState available in constructor instead of componentDidMount

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
awearycommented, Oct 12, 2018

@kafein I’m not going to be doing anything else with this library until React Conf this month. If you can I’d recommend you wait until then.

0reactions
kafeincommented, Nov 30, 2018

Hi @aweary Thanks for explanation. I see the point, you are right. Instead of throwing error on mutate function, we can queue requests then in provider cdm lifecycle we can dequeue and call the requests. Is this reasonable?

Not sure about test but i made a pr. #61

Read more comments on GitHub >

github_iconTop Results From Across the Web

React.Component
React lets you define components as classes or functions. ... perform your work in componentDidMount() or the other lifecycle methods instead.
Read more >
setState called in ComponentDidMount is not updating the ...
I am new to react-native and I am here trying to update the state when the component is loaded. however the state is...
Read more >
React Lifecycle Methods Render And ComponentDidMount
If we are talking about lifecycle methods in React.js then render() is the most used method. If React component has to display any...
Read more >
React lifecycle methods: An approachable tutorial with ...
constructor (); static getDerivedStateFromProps(); render(); componentDidMount(). Updating lifecycle methods. static getDerivedStateFromProps ...
Read more >
React 16 Lifecycle Methods: How and When to Use Them
We need the constructor to call createRef , to create a reference to ... Most Common Use Case for componentDidMount: Starting AJAX calls...
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