Skip to content

Prefetching from API? #1

Closed
Closed

Description

@dvdbrk

Excellent template, thank you.

I am confused as to where would you put an async API call during the server side rendering?
For example to fetch the Pokemon and put it in the initial state alongside the counter value?

  const preloadState: Partial<RootState> = { counter: { value: 88 }};

Activity

  1. StopNGo commented on Nov 18, 2022

    @StopNGo
    Owner

    Hello! Thanks for the evaluation.

    Here is how it should work:
    https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering#server-side-rendering-elsewhere

    So, before preloadState initialization you can do:
    await Promise.all(dispatch(api.util.getRunningQueriesThunk()))
    and insert the result to the preloadState.

    I will try to add prefetching example into the next update.

  2. Repository owner locked and limited conversation to collaborators on Nov 20, 2022
  3. converted this issue into a discussion #2 on Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions