The new React Context API is amazing, however I seem to be always hacking my way around accessing it outside of a React component.. When you are inside a React function component or a React class component everything is great, however when you need to read or reset a value from the context (for example due to an async operation that happens in a fetch function) there is no easy way to do it..
So, is there a way to access the values in React Context Consumer outside a react component?
Later edit: I have inherited a Redux based project and slowly transition out of it. In the action creators, I have a logout function that purges the contents of the store:
export const logoutRequest = () => dispatch => {
navigate('Welcome')
// Reset apollo data
client.resetStore()
persistor.purge()
// Reset context api data HERE
//
}
I could easily create a consumer in the component that calls the logout request, but that happens in 3 different components and I wouldn't want to duplicate the code there..