Answer the question
In order to leave comments, you need to log in
How to add dynamic id in NextJS getServerSideProps?
Please tell me I have a component
export default function Home() {
const [id, setId] = useState(0);
const changeId = () => {
setId(id + 1);
}
return (
<div>
<button onClick={() => changeId()}>Click</button>
</div>
)
}
export async function getServerSideProps(context) {
const res = await fetch(`https://example/:id`); //Вместо :id должен быть id который в компоненте home
const data = await res.json();
return {
props: {data}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question