Next.js
Here are the steps you must take to get Kea set up with Next.js
#
Install the packagesIn addition to the kea
, redux
,
react-redux
and reselect
packages that Kea normally requires, you must also install the
babel-plugin-kea
and
next-redux-wrapper
packages:
#
Set up babel-plugin-keaIn order to properly hydrate your store between server and client renders, we must install the
babel-plugin-kea
package. This ensures that
every kea()
call automatically gets a path
, which help us link the same logic on the client and
the server.
Add this to your .babelrc
:
#
Create _app.jsCreate pages/_app.js
and paste in the following content. The content below is taken from
next-redux-wrapper's readme. Notable changes
have been annotated with comments.
#
UsageFeel free to use kea
calls anywhere in your app now!
If you have a logic
that initializes the data for a page, pass it as the logic
property
on the page's Component: MyPage.logic = logic
.
When this logic is built, it'll get a function resolve
as part of props
. Once your logic
has finished initializing or it crashed, call props.resolve()
to signal that the loading has
finished.
#
Sample appHere is the Github API tutorial app, but adapted to work with Next.js server rendering. All the changes are highlighted with a finger. ๐