react-context

Does new React Context API trigger re-renders?

↘锁芯ラ 提交于 2019-11-27 23:44:06
I have been trying to understand the new React Context API and was playing with it. I just wanted to check a simple case - what all re-renders when data to a Provider is updated. Check this small example on Codesandbox So, in my example, I have an App component - that has state something like this -- this.state = { number - A random number text - A static text } I create a new React Context from here containing number and text from state and pass the values to two Consumers Number and Text . So my assumption is if the random number updates, it will change the context and both the components

Does new React Context API trigger re-renders?

荒凉一梦 提交于 2019-11-27 04:38:19
问题 I have been trying to understand the new React Context API and was playing with it. I just wanted to check a simple case - what all re-renders when data to a Provider is updated. Check this small example on Codesandbox So, in my example, I have an App component - that has state something like this -- this.state = { number - A random number text - A static text } I create a new React Context from here containing number and text from state and pass the values to two Consumers Number and Text .

React Context vs React Redux, when should I use each one? [closed]

强颜欢笑 提交于 2019-11-26 19:25:25
React 16.3.0 was released and the Context API is not an experimental feature anymore. Dan Abramov (the creator of Redux) wrote a good comment here about this, but it was 2 years when Context was still an Experimental feature. My question is, in your opinion/experience when should I use React Context over React Redux and vice versa? As Context is no longer an experimental feature and you can use Context in your application directly and is going to be great for passing down data to deeply nested components which what it was designed for. As Mark erikson has written in his blog : If you're only

Access React Context outside of render function

半世苍凉 提交于 2019-11-26 07:55:35
I am developing a new app using the new React Context API instead of Redux, and before, with Redux , when I needed to get a list of users for example, I simply call in componentDidMount my action, but now with React Context, my actions live inside my Consumer which is inside my render function, which means that every time my render function is called, it will call my action to get my users list and that is not good because I will be doing a lot of unecessary requests. So, how I can call only one time my action, like in componentDidMount instead of calling in render? Just to exemplify, look at

React Context vs React Redux, when should I use each one? [closed]

人盡茶涼 提交于 2019-11-26 04:06:38
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 11 months ago . React 16.3.0 was released and the Context API is not an experimental feature anymore. Dan Abramov (the creator of Redux) wrote a good comment here about this, but it was 2 years when Context was still an Experimental feature. My question is, in your opinion/experience when

Access React Context outside of render function

不问归期 提交于 2019-11-26 02:19:26
问题 I am developing a new app using the new React Context API instead of Redux, and before, with Redux , when I needed to get a list of users for example, I simply call in componentDidMount my action, but now with React Context, my actions live inside my Consumer which is inside my render function, which means that every time my render function is called, it will call my action to get my users list and that is not good because I will be doing a lot of unecessary requests. So, how I can call only