-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd34b26
commit be23ed3
Showing
7 changed files
with
111 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
import { useRouter } from "next/router"; | ||
import { wrapper, pokemonApi, useGetPokemonByNameQuery } from "../../store"; | ||
import {useStore} from "react-redux"; | ||
|
||
export default function Pokemon() { | ||
const { query } = useRouter(); | ||
|
||
console.log('State on render', useStore().getState()); | ||
const { data } = useGetPokemonByNameQuery(query.pokemon as string); // data is undefined for the first render | ||
|
||
if (!data) { | ||
throw new Error("Data is undefined when page is opened by client routing"); | ||
} | ||
|
||
return <div>Name: {data?.name}</div>; | ||
} | ||
|
||
export const getServerSideProps = wrapper.getServerSideProps( | ||
(store) => async (context) => { | ||
const pokemon = context.params?.pokemon; | ||
if (typeof pokemon === "string") { | ||
console.log('DISPATCH'); | ||
store.dispatch(pokemonApi.endpoints.getPokemonByName.initiate(pokemon)); | ||
} | ||
|
||
await Promise.all(pokemonApi.util.getRunningOperationPromises()); | ||
|
||
console.log('SERVER STATE', store.getState().pokemonApi); | ||
|
||
return { | ||
props: {}, | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters