Update your state directly from your components. No reducers, no actions.
npm i oberon-redux
yarn add oberon-redux
This package is designed to provide an interface to using redux that matches the development thought proces. When using redux, generally you need to define your default state, provide reducers to define how your state can get updated and then create an interface to trigger these updates through action creators. We feel it makes more sense to focus on creating components and use the redux state whenever you need to share state between components or component instances (i.e. through persistence). Doing this should not break your workflow or thought process. Therefor with this package, all you need to do to use your redux store is the following:
- Define your initial state.
- Update the state directly from your components.
Updater functions are provided that implement common state update patterns.
For an overview of all available updater functions, refer to the full API documentation
Define your default state
// The default state us just a plain objectcurrentIndex: 0;
Bind the reducer to your redux store
You can add the reducer as the root reducer when creating your store, but we recommend using combine reducers so you have the option to add other redux related packages, for example to manage your api calls and data.
;;const reducer = ;const rootReducer = ;const store = ;
Use the state in your components
;;;// Use react-redux to bind your state and dispatch updates.const mapStateToProps =currentIndex: stateappcurrentIndex;const mapDispatchToProps =;const enhance = ;const MyComponent =<div><div>The current index is propscurrentIndex</div><div>0 1 2 3</div></div>;MyComponent;
Using with TypeScript
This package includes TypeScript type definitions. So type checking on all functions should be enabled by default. To add type checking on the path names given to updater functions, you can use the createStatePaths function to retrieve a StatePathTree. This is a recursive structure that you can use instead of strings when passing the state path to an updater function.
;const paths = ;// somewhere in your component;// is same as;// but with type checking. Catch errors before they happen!