biskut
v1.0.4
Published
Biskut let's you to connect your redux actions in express js server
Readme
This package let's you to connect your redux actions in express js server
Ations.js from client app
dispatch({type: Actions.FECH_DATA, id, xhr: true}) Express router in server side
const api = require("biskut/expressMiddleware")
const handler = async ({id}, req, res, next)=>{
const data = await DB.findById(id)
return {
type: Actions.POST_CREATE_SUCCESS,
data
}
})
const myApi = api({
[Actions.FECH_DATA] : handler
})
app.use(myApi)
Features
- It use action in both server and client to communicate
- fetches the data from server automatically when dispatches the action
- Reducer can modify the store immediately for server response without any extra handler
Getting started
npm install biskutin both server and client side- Create Actions which can use by both server and client
- Update your redux midleware
import createApiMiddleware from 'biskut/reduxMiddleware';
const store = createStore(reducers, initialState, applyMiddleware(
thunkmiddleware, .... other middleware,
createApiMiddleware({ url })
));- Update server code
const expressMiddleware = require("biskut/expressMiddleware")
const Actions = require("../src/Actions.json")
const controller = {
[Actions.FECH_DATA]: <your handler>
}
app.use(api(handlers));
