Resource Reducers
The main export of Redux Resource, resourceReducer, is a function that returns a reducer. For each resource type in your application, you should use this function to create a reducer. A resource reducer will manage all of the state for its resource type.
Creating a resource reducer is the first step to getting started with Redux Resource. If your application manages books, then you would create a reducer for the books resource like so:
1
import { resourceReducer } from 'redux-resource';
2
3
const booksReducer = resourceReducer('books');
Copied!
Once you have your resource reducers, you need to combine them into a single reducer. Users of Redux frequently use combineReducers for this purpose. When you use combineReducers, your store is divided up into slices, where each reducer that you input manages its own section of the state. These sections are often called "slices."
The rest of this documentation will frequently refer to "resource slices," which are the slices of your store that are managed by a resource reducer.
The following code snippet demonstrates how you might set this up:
1
import { combineReducers } from 'redux';
2
import { resourceReducer } from 'redux-resource';
3
4
const reducer = combineReducers({
5
books: resourceReducer('books'),
6
authors: resourceReducer('authors'),
7
people: resourceReducer('people'),
8
});
Copied!
The resourceReducer function takes a second option, which can be used to configure the resource reducer. Refer to the API documentation for resourceReducer to learn more.
Note: keep in mind that Redux Resource works with or without combineReducers.
Copy link