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 promise I tried to make a StackBlitz for this, but it really doesn't like demos that trigger infinite loops 😂
This is kind of a toy example, but if you pass a PathPattern object to useMatch, its memoization starts to fail. That's sneaky, because going from (working) code like this:
const [count, setCount] = useState(0);
const match = useMatch('test');
useEffect(() => setCount((c) => c + 1), [match]);
could be tweaked a bit to pull the values off of the passed in object (if it's an object) instead of forcing each caller to add an additional useMemo to get memoization to work.
I'm using React Router as a...
library
Reproduction
I promise I tried to make a StackBlitz for this, but it really doesn't like demos that trigger infinite loops 😂
This is kind of a toy example, but if you pass a PathPattern object to useMatch, its memoization starts to fail. That's sneaky, because going from (working) code like this:
to this:
introduces an infinite loop.
I think that the memo here:
react-router/packages/react-router/lib/hooks.tsx
Lines 173 to 175 in 5a1ca08
could be tweaked a bit to pull the values off of the passed in object (if it's an object) instead of forcing each caller to add an additional useMemo to get memoization to work.
System Info
Used Package Manager
npm
Expected Behavior
useMatch returns a memoized object when feasible.
Actual Behavior
When you pass in a PathPattern, useMatch's result is no longer memoized.
The text was updated successfully, but these errors were encountered: