I am working on a nextjs project where i have a helpers folder in level with pages folder.
I have a ts file inside helpers folder and here i want to get the latest state and update state depending on the latest state
This is how im getting the state
store().getState()
where store is imported from store.js
Im updating state depending on the previous state
const state = store().getState()
if(!state.currentUser){ // here im checking if state has currentUser
store().dispatch(Action) // here im calling action which will update the state
}
do further operations
The problem here is I'm not getting the updated state from store().getState() after updating the state. Is the way I'm managing things correctly? How to get the updated state?
*EDIT* : Im sending a helper function as a prop to many if my page components. Now that i dont want to touch this , i somehow want to get the updated state and dispatch actions based on the state itself. Note that the hepler function is not a functional component
Thanks in advance