DEV Community

Discussion on: Using React Context for state management in Next.js

Collapse
 
simplenotezy profile image
Mattias Fjellvang

Thanks for the article Cassidy. How would you go about updating the context values? I have an API request that will be fired, and on response, I'd like to update the context.

Collapse
 
cassidoo profile image
Cassidy Williams

You can do that in any state variables you store in the Context! In your example, I'd probably call your API in a useEffect and then set a state variable in that, and then make sure that state variable is passed into Context. Here's an example of that from the Jamstack Explorers GitHub repo: github.com/netlify/explorers/blob/...