Skip to content
This repository has been archived by the owner on Mar 15, 2023. It is now read-only.

ergofriend/react-router-loader-and-relay-preload

Repository files navigation

react-router-loader-and-relay-preload

Relay Render-as-You-Fetch with react-router

react-router

react-relay

0004-06-19.15.43.23.mov

Code

<DataBrowserRouter fallbackElement={<></>}>
  <Route path="/" element={ShipList} loader={shipListQueryLoader} />
  <Route path="/:id" element={ShipDetail} loader={shipDetailLoader} />
</DataBrowserRouter>
export const shipListQueryLoader = () =>
  loadQuery(environment, shipListQuery, {});

export const ShipList = () => {
  const _data = useLoaderData() as PreloadedQuery<ShipListQuery>;
  const data = usePreloadedQuery<ShipListQuery>(shipListQuery, _data);
export const shipDetailLoader: LoaderFunction = ({params}) =>
  loadQuery(environment, shipDetailQuery, { id: params.id });

export const ShipDetail = () => {
  const _data = useLoaderData() as PreloadedQuery<ShipDetailQuery>;
  const { ship } = usePreloadedQuery<ShipDetailQuery>(shipDetailQuery, _data);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published