Store timing with useEffect #107
-
Hi @lostpebble I am wondering what could be best practise as I have an issue with the timing of an update of the store... I have a custom hook that loads and offers my config
Then I have another hook I use as a repository to load data. That hook depends on the configHook. (I think its not really a hook...)
Then I have functional components, that use the backendRepository Hook like
Now my problem is, that when the useEffect is triggered within the InfoPanel component and the backendRepository.getVersion() is called, that the config within the useBackendRepository is empty. Is there any best practice for that? Thanks for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Hi @hohenp , I'm sorry, I've read over your code a few times and I'm very confused as to what could be going wrong- I cannot really understand what it exactly is meant to do... There's probably a much easier way to achieve what you're trying to do here. It looks like you're wrapping many async functions and requests all together in multiple layers and its not easy to reason about. Its very hard for me to debug exactly what could be going wrong here. It may have something to do with the fact that you're calling functions in higher hooks which do things outside of the React "component" pattern- so you're getting state that hasn't been updated yet from the I'd suggest re-looking at the layout of your code here and trying to de-complexify it. Maybe take a look at the Async Actions to make requests which are reliant on actual local component state, and react accordingly. |
Beta Was this translation helpful? Give feedback.
Hi @hohenp ,
I'm sorry, I've read over your code a few times and I'm very confused as to what could be going wrong- I cannot really understand what it exactly is meant to do... There's probably a much easier way to achieve what you're trying to do here. It looks like you're wrapping many async functions and requests all together in multiple layers and its not easy to reason about.
Its very hard for me to debug exactly what could be going wrong here. It may have something to do with the fact that you're calling functions in higher hooks which do things outside of the React "component" pattern- so you're getting state that hasn't been updated yet from the
GlobalStore.useState()
hook- or an …