Created
January 7, 2022 08:35
-
-
Save sand97/654533dba88eefb7cc861d8607729c40 to your computer and use it in GitHub Desktop.
nextjs get server side props example
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
const Product = (props) => { | |
return <div> | |
{ props.data.map(p => <div key={p.id}>{p.name}</div>) } | |
</div> | |
} | |
export const getServerSideProps = async (context) => { | |
const {name} = context.query | |
//you can fetch data from your api like this | |
// const res = await | |
// fetch(`api.yourcms.com/product?keyword=${name}`); | |
return { | |
props: {data: [{name: 'Banana', id: 1}, | |
{name: 'Potato', id: 2}] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment