react-crud
Install
Install this package with npm
npm i @salsita/react-crud
or yarn
yarn add @salsita/react-crud
API
Modules
Constants
-
withRouterParams ⇒
function
-
Creates a composed effectParamsFactory which automatically passes current route params to effectParamsFactory
Functions
-
crudReducer(state, action) ⇒
CrudState
-
The reducer of the crud module
-
saveEntity(entityData, entity, mapEntityToSaveParams, [form]) ⇒
Object
-
Creates or updates entity from form data
After entity has been saved, it reflects the data back into entity repository.
- crudSaga(mapRouteToFetchParams)
-
This saga has to be forked in the root saga of the app
CrudActions
Action
CrudActions.entitiesFetched(route, key, result) ⇒ Saves result of normalized data for a route
Kind: static method of CrudActions
Param | Type | Description |
---|---|---|
route | string |
Route name |
key | string |
Key of entity |
result |
number | Array.<number>
|
ID or IDs of entities (the result of normalization) |
function
withRouterParams ⇒ Creates a composed effectParamsFactory which automatically passes current route params to effectParamsFactory
Kind: global constant
Returns: function
- Composed effectParamsFactory
Param | Type | Description |
---|---|---|
effectParamsFactory | function |
to be wrapped |
CrudState
crudReducer(state, action) ⇒ The reducer of the crud module
Kind: global function
Param | Type | Description |
---|---|---|
state | CrudState |
The state of the crud module |
action | Action |
A redux action |
Object
saveEntity(entityData, entity, mapEntityToSaveParams, [form]) ⇒ Creates or updates entity from form data
After entity has been saved, it reflects the data back into entity repository.
Kind: global function
Returns: Object
- updated entity
Param | Type | Description |
---|---|---|
entityData | Object |
Entity data |
entity | string |
Entity type |
mapEntityToSaveParams | function |
A function that maps an entity to the save params |
[form] | string |
Id of the form |
crudSaga(mapRouteToFetchParams)
This saga has to be forked in the root saga of the app
Kind: global function
Param | Type | Description |
---|---|---|
mapRouteToFetchParams | function |
A function that maps a route to the fetch params |