Installation Instructions
note
If you're using a JS framework such as next.js, check out the detailed instructions for it. The instructions below should work for most setups though.
#
Shortcut: CRA templateTo create a new app based on kea's create-react-app typescript template, run the following:
This sets up a new project with kea
and kea-typegen
, and adds
the plugins kea-router
and kea-loaders
. It's the fastest way to just try out Kea.
#
Install Kea manuallyInstalling kea
is rather straightforward. You need to install some packages, optionally call resetContext
and wrap your app with a <Provider />
tag.
#
1. Install some packagesIn addition to kea
you will also need redux
,
react-redux
and reselect
.
#
2. Set up Kea's contextKea stores all of its data on a context, which must be set up before any logic
can be used. This
context stores a reference to the redux store, initializes all plugins, caches all built logic and keeps
track of what is mounted and what is not.
To set it up, just call resetContext(options)
before rendering your app.
<Provider />
#
3. Wrap with Then wrap your <App />
with <Provider />
.
This is how your index.js
would look like if you used create-react-app
:
That's it! Feel free to use kea()
calls anywhere in your code!
#
4. TypeScript supportIf you're using TypeScript (and everybody should), you'll need to set up kea-typegen as well.
First, run the following:
Then add the following to your .gitignore
:
Finally, change your start script in package.json
Read more about TypeScript Support in Kea.
Next Steps
- Read Core Concepts to get a good understanding of how Kea works and why.