Skip to content

Commit

Permalink
Use getServerSideProps (#11057)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Alvarez D authored Mar 13, 2020
1 parent 925d843 commit 7bf7c23
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/api-routes/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Index = ({ people }) => (
</ul>
)

export async function getStaticProps() {
export async function getServerSideProps() {
const response = await fetch('http://localhost:3000/api/people')
const people = await response.json()

Expand Down
15 changes: 1 addition & 14 deletions examples/api-routes/pages/person/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,7 @@ const Person = ({ data, status }) =>
<p>{data.message}</p>
)

export async function getStaticPaths() {
const response = await fetch('http://localhost:3000/api/people')
const data = await response.json()

const paths = data.map(person => ({
params: {
id: person.id,
},
}))

return { paths, fallback: false }
}

export async function getStaticProps({ params }) {
export async function getServerSideProps({ params }) {
const response = await fetch(`http://localhost:3000/api/people/${params.id}`)
const data = await response.json()

Expand Down

0 comments on commit 7bf7c23

Please sign in to comment.