Skip to content
Discussion options

You must be logged in to vote

With defer, Remix expects you to return the Promise, not the awaited value. If you await the promise, Remix will wait until it is resolved before rendering.

I created a PR in your repo.

export const clientLoader = async () => {
  const myPromise = new Promise<string>((resolve) => {
    setTimeout(() => {
      resolve(Math.random().toString());
    }, 2000);
  });
  // return the promise
  return defer({ myPromise });
};

function SearchResults() {
  const { myPromise } = useLoaderData<typeof clientLoader>();

  return (
    <div>
        Show me straight away
        <div>
            <Suspense fallback={<div>Loading locally</div>}>
                {/* here is where Remix awaits the prom…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@andrewbarnesweb
Comment options

@TheBuilderJR
Comment options

@kiliman
Comment options

@andrewbarnesweb
Comment options

@TheBuilderJR
Comment options

Answer selected by andrewbarnesweb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants