Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions documentation/docs/guides-and-concepts/ssr-nextjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ export const getServerSideProps: GetServerSideProps = async () => {

### SSR

`NextRouteComponent` accepts a `pageData` prop for SSR data.
`NextRouteComponent` accepts a `initialData` prop for SSR data.

```ts
type NextRouteComponentProps = {
pageData?: any;
initialData?: any;
};
```
`pageData` must be passed as props from `getServerSideProps`. `NextRouteComponent` will pass this data as `initialData` to the `list`, `create`, `edit` and `show` components.
`initialData` must be passed as props from `getServerSideProps`. `NextRouteComponent` will pass this data as `initialData` to the `list`, `create`, `edit` and `show` components.

For example, for a `list` component that will be rendered for `/[resource]`, the page can use SSR like this:

Expand All @@ -228,7 +228,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {

return {
props: {
pageData: data,
initialData: data,
},
};
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion examples/refine-next/pages/[resource]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {

return {
props: {
pageData: data,
initialData: data,
},
};
} catch (error) {
Expand Down
18 changes: 12 additions & 6 deletions packages/nextjs-router/src/nextRouteComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import { RouterProvider } from "./routerProvider";
const { useHistory, useLocation, useParams } = RouterProvider;

type NextRouteComponentProps = {
pageData?: any;
initialData?: any;
};

export const NextRouteComponent: React.FC<NextRouteComponentProps> = ({
pageData,
initialData,
children,
...rest
}) => {
const { resources } = useResource();
const { push } = useHistory();
Expand Down Expand Up @@ -77,7 +79,8 @@ export const NextRouteComponent: React.FC<NextRouteComponentProps> = ({
canEdit={canEdit}
canDelete={canDelete}
canShow={canShow}
initialData={pageData}
initialData={initialData}
{...rest}
/>
);
}
Expand All @@ -90,7 +93,8 @@ export const NextRouteComponent: React.FC<NextRouteComponentProps> = ({
canEdit={canEdit}
canDelete={canDelete}
canShow={canShow}
initialData={pageData}
initialData={initialData}
{...rest}
/>
);
}
Expand All @@ -103,7 +107,8 @@ export const NextRouteComponent: React.FC<NextRouteComponentProps> = ({
canEdit={canEdit}
canDelete={canDelete}
canShow={canShow}
initialData={pageData}
initialData={initialData}
{...rest}
/>
);
}
Expand All @@ -116,7 +121,8 @@ export const NextRouteComponent: React.FC<NextRouteComponentProps> = ({
canEdit={canEdit}
canDelete={canDelete}
canShow={canShow}
initialData={pageData}
initialData={initialData}
{...rest}
/>
);
}
Expand Down