This is a plugin that only has a peer dependency to
piral-redux brings to the table is a set of Pilet API extensions that can be used with
piral-core for including a state container managed by Redux.
By default, these API extensions are not integrated in
piral, so you'd need to add them to your Piral instance.
The following functions are brought to the Pilet API.
Creates a new Redux store for the pilet. The store is tighly coupled to the lifetime of the pilet.
This function returns the
connect function known from React Redux - just applied to the pilet store.
For authors of pilets
Use the function
createReduxStore to obtain a store connector. The store connector is a higher-order component that wraps an existing component and removes the
dispatch props. Instead,
state will be "connected" to the created pilet store and
dispatch allows modifying the state by calling the reducer with the provided action.
Let's see a full example.
The reducer could be defined such as:
Using this construct is straight forward and follows other
create... Pilet APIs.
Setup and Bootstrapping
For Piral instance developers
The provided library only brings API extensions for pilets to a Piral instance.
For the setup of the library itself you'll need to import
createReduxApi from the
The integration looks like:
There are two options available. The
reducer option allows us to define reducers that also access and manipulate the global state. The
enhancer option allows us to pass in a custom store enhancer. For more details on enhancers please look at the Redux documentation.
Piral is released using the MIT license. For more information see the license file.