I have been wasting hours and HOURS trying to figure out how to call a trpc query on the first render only.
I am querying data that populates a drop down select input. When an option is selected, my state updates and the component re-renders which calls the data again.
I don't want to call the data again.
1. I can't call it inside of useEffect because it breaks the rules of hooks.
2. I've also tried wrapping the query in a useCallback & returning the data to set inside of a useEffect but I just get a "prevDeps is undefined" error.
Another error that I've seen is "observer.getOptimisticResult is not a function" if I just use useCallback without useEffect. Weird stuff.
Does anyone have any suggestion on how to do this?
With a code example :/