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.

Implement global state life cycle methods.

See original GitHub issue

Hi,

I have experiment this behavior :

  • I use this.global.x in componentDidUpdate in component A
  • When component B updates global.x, component A doesn’t rerender
  • I make something else to make component A render
  • Then when component B updates global.x it does make component A render

I suppose that before the first call of componentDidUpdate, we don’t know that component A is using global.x, so it is not rerendered until something make it call componenetDidUpdate, at this time we see that component A uses global.x.

I am not sure my issue is clear, is it the expected behavior or do you think it can be changed ?

Thank you

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
CharlesStovercommented, Nov 27, 2018

They are both based on the React naming convention. One is the React method + Global, while the other is the React method replacing Component with Global. But the React method + Global is probably more clear as to what it is doing, so I will go with that. e.g. You aren’t determining if the global state should update.

2reactions
CharlesStovercommented, Nov 26, 2018

I also would prefer the first one because we can they mix operation between prevProps, prevState and prevGlobal.

I agree, but I think it is a limitation. ReactN does not modify React or React Fiber. The dispatch of component lifecycle methods is handled by React Fiber. Customizing them can’t be done without modifying React Fiber. A major advantage of ReactN is that it does not mutate React or its internals, allowing for a simultaneous install of the two packages and guaranteed non-interference.

I may go with the last choice and implement lifecycle methods for global. I also like the idea of shouldComponentUpdateGlobal (or shouldGlobalUpdate), not sure which naming convention to adopt yet.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React lifecycle methods: An approachable tutorial with examples
Learn all about React lifecycle methods for mounting, updating, unmounting, and error handling, including new methods as of React 17.
Read more >
State and Lifecycle - React
This page introduces the concept of state and lifecycle in a React component. You can find a detailed component API reference here.
Read more >
React 16 Lifecycle Methods: How and When to Use Them
If you're not super comfortable with React, my article here provides a thorough intro.
Read more >
What Are Lifecycle Methods and Why Do We Use Them in ...
React lifecycle methods play a significant role in building projects in React. It's essential to understand just what they are and how to ......
Read more >
React Lifecycle - W3Schools
The getDerivedStateFromProps() method is called right before rendering the element(s) in the DOM. This is the natural place to set the state object...
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