If I use Match, useMatch, or useParams, I actually want to react only to changes in the corresponding parts of location. But right now my components rerender on each location change, even if it's irrelevant.
One possible solution would be to put history into React context, and implement something like useLocationSelector(location => ...), similar to useSelector from React Redux. It would only rerender if selector returns a different value. Then, useMatch, useParams, and Match could be re-implemented on top of useLocationSelector. Something like useParam(paramName) would be also useful then: it would react to changes in the selected param only
If I use
Match
,useMatch
, oruseParams
, I actually want to react only to changes in the corresponding parts of location. But right now my components rerender on each location change, even if it's irrelevant.One possible solution would be to put
history
into React context, and implement something likeuseLocationSelector(location => ...)
, similar touseSelector
from React Redux. It would only rerender if selector returns a different value. Then,useMatch
,useParams
, andMatch
could be re-implemented on top ofuseLocationSelector
. Something likeuseParam(paramName)
would be also useful then: it would react to changes in the selected param onlyI can open a PR if this idea makes sense to you.
A couple of links for more context: https://github.com/facebook/react/issues/15156 https://blog.isquaredsoftware.com/2018/11/react-redux-history-implementation/#v7-0