TanStackT
TanStack12mo ago
13 replies
foolish-indigo

can useSearch be used from inside a portal?

I have a component that if the width of the screen is smaller than 992 renders the content inside a portal outside the div that contains the main react app
If I don't use the portal everything works as expected, but if I add the portal, the useSearch works as expected when loading, but, when moving to a different page I get Could not find a nearest match!
I'm using just strict false as the useSearch parameters, inspecting the error I think I found why this is happening, inside the useMatch function called by the useSearch, its not returning a match (image 1) since my nearestMatchId is /category/_category/$casual (which is the page I was previously on) and state.matches only includes root route and the route im going to.
image.png
Was this page helpful?