Hi Kent, glad to know about the new context API and the samples handle the issue of prop drilling. I am curious if the new context API can handle the issue of updating context between components. That is: if one child component modify the context/prop, will or how other child components get the update? Any sample?
My name is Kent C. Dodds and I'm a Remix Co-Founder, JavaScript engineer, and teacher. I'm also active in the open source community. I like my family, JavaScript, and React.
Yes definitely, in my examples the provider exposes a mechanism for updating the context value and the consumer components use that mechanism to update the context value. So yes, this is definitely supported.
Got it and thanks. Then for Redux, to modify the store's state, one action must be dispatched from View/Component. For new Context API, how to modify the context value? Any special restriction?
My name is Kent C. Dodds and I'm a Remix Co-Founder, JavaScript engineer, and teacher. I'm also active in the open source community. I like my family, JavaScript, and React.
Well, if you were to put the redux store into the provider component, then it could expose the dispatch from the store for consumers and the provider could subscribe to updates and call setState on itself which would re-render and update the context value which would rerender subscribers.
Hi Kent, glad to know about the new context API and the samples handle the issue of prop drilling. I am curious if the new context API can handle the issue of updating context between components. That is: if one child component modify the context/prop, will or how other child components get the update? Any sample?
Yes definitely, in my examples the provider exposes a mechanism for updating the context value and the consumer components use that mechanism to update the context value. So yes, this is definitely supported.
Got it and thanks. Then for Redux, to modify the store's state, one action must be dispatched from View/Component. For new Context API, how to modify the context value? Any special restriction?
Well, if you were to put the redux store into the provider component, then it could expose the dispatch from the store for consumers and the provider could subscribe to updates and call
setState
on itself which would re-render and update the context value which would rerender subscribers.Great thanks!