All Projects → haoxins → redux-action

haoxins / redux-action

Licence: other
🍻 Flux action utilities for Redux

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to redux-action

fetch-action-creator
Fetches using standardized, four-part asynchronous actions for redux-thunk.
Stars: ✭ 28 (+12%)
Mutual labels:  react-redux, redux-actions
boss
React+express+sock.io+mongodb build a boss
Stars: ✭ 25 (+0%)
Mutual labels:  react-redux
redux-actions-helpers
Small helpers functions for creating and handle redux actions
Stars: ✭ 35 (+40%)
Mutual labels:  redux-actions
admin-template-for-react
🌏 Admin template for React, React Redux, Redux Saga, React Router, i18n and integrated OAuth login
Stars: ✭ 83 (+232%)
Mutual labels:  react-redux
book-fullstack-react
Fullstack React: The Complete Guide to ReactJS and Friends by Anthony Accomazzo
Stars: ✭ 100 (+300%)
Mutual labels:  react-redux
redux-routines
👷 Predefined actions creators and action types for common async tasks in a single object called "routine"
Stars: ✭ 12 (-52%)
Mutual labels:  redux-actions
material-ui-responsive-drawer
Material-UI responsive Drawer is a React-Redux component that uses Material-UI to create a responsive Drawer.
Stars: ✭ 44 (+76%)
Mutual labels:  react-redux
react-cli
基于 create-react-app 搭建的前端脚手架
Stars: ✭ 18 (-28%)
Mutual labels:  react-redux
energy-use-case-trading-client
Energy Use Case Web UI for Lition Trading Platform
Stars: ✭ 23 (-8%)
Mutual labels:  react-redux
react-candee
A react framework that encapsulates the redux.
Stars: ✭ 30 (+20%)
Mutual labels:  react-redux
eshop
e-commerce website built with reactjs & redux on the frontend and lumen on the backend.
Stars: ✭ 27 (+8%)
Mutual labels:  react-redux
react-ssr
从零搭建一个react-ssr框架 解决页面js事件 样式同构 服务器客户端路由 数据注水脱水等问题
Stars: ✭ 42 (+68%)
Mutual labels:  react-redux
Turbo-Browser
Simple & Secure Internet mobile browser built on React Native.
Stars: ✭ 25 (+0%)
Mutual labels:  react-redux
redux-analysis
《学习源码整体架构系列》多篇之redux源码,前端面试高频源码,微信搜索「若川视野」关注我,长期交流学习~
Stars: ✭ 28 (+12%)
Mutual labels:  react-redux
oc-redux
oc 版简易 redux 实现
Stars: ✭ 21 (-16%)
Mutual labels:  react-redux
isomorphic-react-redux-saga-ssr
Isomorphic, React, Redux, Saga, Server Side rendering, Hot Module Reloading, Ducks, Code Splitting
Stars: ✭ 19 (-24%)
Mutual labels:  react-redux
react-use-redux
Alternative Redux bindings with upcoming React hooks
Stars: ✭ 31 (+24%)
Mutual labels:  react-redux
ssr
React Server-Side Rendering Example
Stars: ✭ 265 (+960%)
Mutual labels:  react-redux
react-native-boilerplate
Expo + Redux + React Navigation Pre-setup Template (expo SDK 44)
Stars: ✭ 142 (+468%)
Mutual labels:  react-redux
Covid19-Stats-IN
This app helps in tracking COVID-19 cases in India using covid19India apis
Stars: ✭ 13 (-48%)
Mutual labels:  react-redux

Build status Test coverage NPM version License Dependency status

redux-action

import { createAction, createReducer } from 'redux-action'
  • Uses dispatch with Promise chain
  • Generates action type automatically when no pass action type
  • payload first reducer
  • Assign updated data to state automatically
  • Works with redux-thunk

APIs

  • createAction
import { createAction } from 'redux-action'

const action = createAction('action', (...args) => {
  // ...
  return payload
})

const asyncAction = createAction('async action', (...args) => {
  // ...
  return Promise.resolve(payload)
})
  • createReducer
import { createReducer } from 'redux-action'

const reducer = createReducer(defaultState, {
  'action': (payload, state, action) => {
    // ...
    // only return updated state
    // will assign to state automatically
    return updatedData
  },

  'async action': (payload, state, action) => {
    // ...
    return updatedData
  },

  'common usage': payload => ({some: payload}),
})
  • Uses dispatch with Promise
class App extends React.Component {
  async updateData(data) {
    const {
      dispatch,
      userId
    } = this.props

    await dispatch(updateUserInfo(userId, data))
    await dispatch(getUserInfo(userId))
    // ...
  }

  render() {
    // ...
  }
}

Full example

  • store.js
import { createStore, applyMiddleware } from 'redux'
import reduxThunk from 'redux-thunk'
import reducer from './reducer'

const createStoreWithMiddleware = applyMiddleware(
  reduxThunk
)(createStore)

const store = createStoreWithMiddleware(reducer)

export default store
  • action.js
import { createAction } from 'redux-action'

export const setUserStatus = createAction('set user status', status => status)
export const getUserInfo = createAction('get user info', () => Promise.resolve(userInfo))
  • reducer.js
import { createReducer } from 'redux-action'
import { combineReducers } from 'redux'

const defaultState = {
  status: 'normal',
  info: {},
}

const user = createReducer(defaultState, {
  'set user status': status => ({status}),
  'get user info': info => ({info}),
})

// combine reducers

const rootReducer = combineReducers({
  user,
})

export default rootReducer

Auto generated action type

createAction also can generate a unique type, when no pass any string in the first argument.

  • action.js
import { createAction } from 'redux-action'

export const setUserStatus = createAction(status => status)
export const getUserInfo = createAction(() => Promise.resolve(userInfo))
  • reducer.js
import { createReducer } from 'redux-action'

import {
  setUserStatus,
  getUserInfo
} from './action'

const defaultState = {
  status: 'normal',
  info: {},
}

const user = createReducer(defaultState, {
  [setUserStatus]: status => ({status}),
  [getUserInfo]: info => ({info}),
})

See also

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].