Implement global state life cycle methods.
See original GitHub issueHi,
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:
- Created 5 years ago
- Comments:14 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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
(orshouldGlobalUpdate
), not sure which naming convention to adopt yet.