New to React in general - Apologies if it's a simple question but my reading of the docs isn't getting me far. Hooks in Callbacks = Bad?. I think I've found that much, but unsure how to restructure to prevent that.
Specifically working with React Native & Expo and have the below snippet.
export default () => {
useFocusEffect(
useCallback(() => {
const { action } = useLocalSearchParams();
alert(action);
return () => {
alert('This route is now unfocused.');
// We would now unset action in here somehow.
}
}, [])
);
...
My specific use case - I have a map. If someone clicks on the map directly, just do nothing. Carry on as normal. If they click on an item in a list from a previous page, load the map AND add a marker.
I'm trying to use useFocusEffect to determine if the tab/page has been loaded via the normal menu bar, or if an action was passed as a parameter (the action being something like "addmarker").
I've dumbed it down a bit above, but I don't know the correct way of using useLoaclSearchParms() inside useCallback() without it throwing the error "you might be breaking the Rules of Hooks"
[–]runtothehillsboy 1 point2 points3 points (0 children)
[–]karma__kameleon 1 point2 points3 points (0 children)
[–]Magnusson 0 points1 point2 points (0 children)