Next.js
Notes
In order to make pages dynamic, we can wrap them in square brackets, e.g. [id] , then we can get access to them as props:
This code is going to return hello we pass in in the url after /id/hello
We can make it more inclusive by saying [...id], this is going to make it behave like anything coming after id, still going to render the same page
In order to mark a component as a client side component, we need to add
use client
on the top of it. By default the Next.js components are server side components. For running side effect actions we can useuse server
to mark it.We can create loading and error pages by creating
loading.tsx
anderror.tsx
pages, which are going to render in case of loading and errorFor saving data from the form, we can refer to the formData object and get the data from there, like in this helper function:
The counterpart of this code from the component is:
If you want to make an api you can do it by making an api folder in the app. And then you can make a special file called
route
to define your api. Client-side things havepage.tsx
api's haveroute.ts
.Next.Js API example:
Every component by default is server-side component.
Last updated
Was this helpful?