Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
fix(examples): fix examples for getStaticPaths
Browse files Browse the repository at this point in the history
  • Loading branch information
fostyfost committed Oct 4, 2021
1 parent bf0f5f6 commit 9ed7157
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 42 deletions.
46 changes: 25 additions & 21 deletions examples/example-next-gip/pages/users-ids/gsp/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const UserPage: NextPage<InferGetStaticPropsType<typeof getStaticProps>> = ({ ti
const wrapper = wrapperInitializer.getPageWrapper([getUsersEgg()])

export const getStaticPaths = wrapper.wrapGetStaticPaths(store => async () => {
store.addEggs([getUsersEgg()])

store.dispatch(UsersPublicAction.loadUsers())

await waitForLoadedState(store, isUsersLoaded)
Expand All @@ -45,34 +47,36 @@ export const getStaticPaths = wrapper.wrapGetStaticPaths(store => async () => {
}
})

export const getStaticProps: GetStaticProps<Props, InferGetStaticPathsQueryType<typeof getStaticPaths>> =
wrapper.wrapGetStaticProps(store => async context => {
const id = Number(context.params?.id)
export const getStaticProps: GetStaticProps<
Props,
InferGetStaticPathsQueryType<typeof getStaticPaths>
> = wrapper.wrapGetStaticProps(store => async context => {
const id = Number(context.params?.id)

if (!id) {
return {
notFound: true,
}
if (!id) {
return {
notFound: true,
}
}

store.dispatch(UsersPublicAction.loadUsers())

await waitForLoadedState(store, isUsersLoaded)
store.dispatch(UsersPublicAction.loadUsers())

const user = getUserById(store.getState(), id)
await waitForLoadedState(store, isUsersLoaded)

if (!user) {
return {
notFound: true,
}
}
const user = getUserById(store.getState(), id)

if (!user) {
return {
props: {
title: `This is page of user with ID: ${id}`,
id,
},
notFound: true,
}
})
}

return {
props: {
title: `This is page of user with ID: ${id}`,
id,
},
}
})

export default wrapper.wrapPage(UserPage)
46 changes: 25 additions & 21 deletions examples/example-next/pages/users-ids/gsp/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const UserPage: NextPage<InferGetStaticPropsType<typeof getStaticProps>> = ({ ti
const wrapper = wrapperInitializer.getPageWrapper([getUsersEgg()])

export const getStaticPaths = wrapper.wrapGetStaticPaths(store => async () => {
store.addEggs([getUsersEgg()])

store.dispatch(UsersPublicAction.loadUsers())

await waitForLoadedState(store, isUsersLoaded)
Expand All @@ -45,34 +47,36 @@ export const getStaticPaths = wrapper.wrapGetStaticPaths(store => async () => {
}
})

export const getStaticProps: GetStaticProps<Props, InferGetStaticPathsQueryType<typeof getStaticPaths>> =
wrapper.wrapGetStaticProps(store => async context => {
const id = Number(context.params?.id)
export const getStaticProps: GetStaticProps<
Props,
InferGetStaticPathsQueryType<typeof getStaticPaths>
> = wrapper.wrapGetStaticProps(store => async context => {
const id = Number(context.params?.id)

if (!id) {
return {
notFound: true,
}
if (!id) {
return {
notFound: true,
}
}

store.dispatch(UsersPublicAction.loadUsers())

await waitForLoadedState(store, isUsersLoaded)
store.dispatch(UsersPublicAction.loadUsers())

const user = getUserById(store.getState(), id)
await waitForLoadedState(store, isUsersLoaded)

if (!user) {
return {
notFound: true,
}
}
const user = getUserById(store.getState(), id)

if (!user) {
return {
props: {
title: `This is page of user with ID: ${id}`,
id,
},
notFound: true,
}
})
}

return {
props: {
title: `This is page of user with ID: ${id}`,
id,
},
}
})

export default wrapper.wrapPage(UserPage)

1 comment on commit 9ed7157

@vercel
Copy link

@vercel vercel bot commented on 9ed7157 Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.