You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using nested child routes to show & hide modals when the route changes. For example I have the route users and then when pressing a user it navigates to users/:id. This presents a modal component with the user info. This works fine however we want fetch data when a route is navigated to, e.g. the user list, or the user data. I'm trying to do this with a useEffect e.g.
The issue I'm having is that the useEffect is triggered on the parent page when the child route is opened because the route params change. The log from the above example looks like this.
# First load
/users {}
# After showing a modal
/users/1 { id: 1 }
This means that the parent page is running the useEffect whenever you open a modal, and as we're using this to fetch data it's not really ideal. We can't use the loader functionality on the route because we need to pass the ViewModel to that function which isn't supported.
Does anyone have any ideas on how to work around this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm using nested child routes to show & hide modals when the route changes. For example I have the route
users
and then when pressing a user it navigates tousers/:id
. This presents a modal component with the user info. This works fine however we want fetch data when a route is navigated to, e.g. the user list, or the user data. I'm trying to do this with auseEffect
e.g.The issue I'm having is that the useEffect is triggered on the parent page when the child route is opened because the route params change. The log from the above example looks like this.
This means that the parent page is running the useEffect whenever you open a modal, and as we're using this to fetch data it's not really ideal. We can't use the
loader
functionality on the route because we need to pass the ViewModel to that function which isn't supported.Does anyone have any ideas on how to work around this?
Thanks,
Alex
Beta Was this translation helpful? Give feedback.
All reactions