remix-run / react-router

Declarative routing for React
https://reactrouter.com
MIT License
52.41k stars 10.18k forks source link

Expose routing promises #11564

Open ryanflorence opened 1 month ago

ryanflorence commented 1 month ago

In order for React Router transitions to compose with React 19 transitions we need to expose the promises from all of our transition functions:

navigate()
submit()
fetcher.submit()
fetcher.load()
revalidator.revalidate()

This way developers can call into React Router from inside a React transition

let [isPending, startTransition] = useTransition()
startTransition(async () => {
  let stuff = await doSomething()
  let more = await fetcher.submit({ stuff }, { method: "post" })
});

Will add in 7.1

bluefire2121 commented 1 month ago

Very cool! I guess you can do this as well.

const [isPending, startTransition] = useTransition()
startTransition(async () => {
  const [more, stuff] = await Promise.all([fetcher.submit({ stuff }, { method: "post" }), doSomething()]);
});