#Unable to use useNavigate inside async function and I don't know how to do this

1 messages · Page 1 of 1 (latest)

cobalt roost
#

after setting the token and all I'm trying to navigate the user to another url, I don't think this is the right way to do this but I'm a bit confused, I'm using reactjs with Vite and react-router-dom 7.0.1,Thanks

#

Unable to call useNavigate or UseRef, please let me know if there's anything else I need to clarify

compact shuttle
#

You can't use any hooks outside of react components. To redirect from a loader or action import redirect from react-router and throw it.

throw redirect('/somewhere/to/go');
cobalt roost
#

Thanks, let me try this

#

This worked but it's triggering a reload, are there any alternatives?

velvet topaz
#

@cobalt roost It shouldn't be triggering a reload

#

Just made a little reproduction and you can see there's no full reload. The input in the root route maintains its state

#

Here's the code for the index route

#

There's the repo if you'd like to look

cobalt roost
#

Thanks, I'll look into the repo it seems to be a mistake from my part, thank you really for being so helpful, am I supposed to use the action and loader with React js and resct-router-dom package?

#

Again, I just checked out the repo, it seems to be in remix and I'm using react, will that be an issue?

high schooner
#

legend out here helping people on discord

#

nice to see

#

🤘

#

big fan btw

i think i sent u a comment on x like way back

#

hahaha

#

yeah DMs still there

#

again big fan

good stuff

velvet topaz
#

haha thank you brother!

velvet topaz
#

I believe it should be the same

cobalt roost
#

Yeah, let me try that

#

Yes, it does not trigger a reload and it's working, thanks a lot @velvet topaz