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
When using useParams it seems to re-renders on every param change. I don't want this because I have a component that is only interested in changes for a single parameter. Is there any way that I can subscribe to changes for a single parameter?
Maybe a new api is needed? Something like this (untested):
function useParam(name: string) {
const router = useContext(UNSAFE_DataRouterContext)
const [value, setValue] = useState(() => {
const match = subscriber.matches[subscriber.matches.length-1]
return match.params[name]
})
useEffect(() => {
router.subscribe(() => {
const match = subscriber.matches[subscriber.matches.length-1]
setValue(match.params[name])
})
}, [router])
return value
}
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
-
When using useParams it seems to re-renders on every param change. I don't want this because I have a component that is only interested in changes for a single parameter. Is there any way that I can subscribe to changes for a single parameter?
Maybe a new api is needed? Something like this (untested):
Beta Was this translation helpful? Give feedback.
All reactions