I know that one of the fixed rules in React is that you cannot execute any hooks inside methods in a functional component or even inside other hooks like the useEffect hook. It must be executed in the body of the component itself.
So today while working on a quiz app, I ran into a situation where, after passing a screen on the stack navigator, I want to go back to that screen again by clicking on the back button. But this time, I want to modify the info on the previous screen with data from a graphql query using the useQuery hook provided by Apollo Client.
I can detect if the previous screen is focus using the isFocused
property on the props. If it changes, then I will fetch data again using useQuery.
I can do this simply like so:
React.useEffect(() => {
//how do I fetch data from here using useQuery if React prohibits me to use useQuery here?
}, [props.isFocused]);
So that is my question, is there a way around this? I'll appreciate your response.