Installation is as simple as running the npm command:
If you want to update all your @rematch packages to next features you can try:
Model brings together state, reducers, async actions in one place. It describes a slice of your redux store and how it changes.
Understanding configuration of models is as simple as answering a few questions:
- What is my initial state? state
- How do I change the state? reducers
- How do I handle async actions? effects with async/await
Below we define a simple model
- Use helper method
createModelto create a model.
- You must pass the
RootModeltype that is exported on your index.ts of your models.
- State is automatically infered, if your state contains complex types you only need to use an
asLook at count-react-ts example on questions.ts
All the examples of Rematch with Typescript are fully tested in our testing suite, so feel free to look at the /examples folder for an easier integration with your codebase.
Example with a more complex state
init is the only method you need to call to build a fully configured Redux store. You can visit api reference to learn more about all configuration parameters that can be used but as a bare minimum it is enough to provide
models object. It should contain mapping from a model name to model definition (created in step 1).
With dispatch you can trigger reducers & effects in your models. Dispatch standardizes your actions without the need for writing action types or action creators. Dispatch can be called directly, just like with plain Redux, or with the
Rematch can be used with native redux integrations such as "react-redux". See an example below.