diff --git a/README.md b/README.md index 9fada2e..8d3f818 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,4 @@ Technology-specific guidelines - [React Guidelines](/react-guidelines.md) +- [Next.js Guidelines](/nextjs-guidelines.md) diff --git a/nextjs-guidelines.md b/nextjs-guidelines.md new file mode 100644 index 0000000..248256d --- /dev/null +++ b/nextjs-guidelines.md @@ -0,0 +1,48 @@ +- [Introduction](#introduction) + - [Directory Structure](#directory-structure) + - [Layouts](#layouts) + - [Data Fetching \& State Management](#data-fetching--state-management) + - [HOWTOs:](#howtos) + - [HOWTO: SSR + Hookstate.js](#howto-ssr--hookstatejs) + - [HOWTO: SSR + Rematch](#howto-ssr--rematch) + +# Introduction + +## Directory Structure +Use [the src directory](https://nextjs.org/docs/advanced-features/src-directory) and follow the [React Guidelines - Directory Structure](/react-guidelines.md#directory-structure). + +## Layouts +Dynamically import layouts and render them in the `App` component as this prevents the layout component to lose its state upon navigation. + +Set the desired layout name and properties on object properties of the page component: +```tsx +// pages/index.tsx + +setLayout(HomePage, "SomeLayout", { props: { foo: 'bar' } }) +``` + +You can then retrieve the layout component and properties in the `App` component: +```tsx +// pages/app.tsx + +export default function App({ Component, pageProps }: AppProps) { + const [Layout, layoutProps] = usePageLayout(Component) + + return ( + + + + ) +} +``` + +## Data Fetching & State Management +Please read [React Guidelines](/react-guidelines.md#state-management) first. + +### HOWTOs: + +#### HOWTO: SSR + Hookstate.js +TODO. + +#### HOWTO: SSR + Rematch +TODO.