store-renew

1.1.3 • Public • Published

store-renew

when you are coding with redux, you may need to return a new state every time you deel with a reducer, just like this.

const reducer = (state, { payload }) => {
  return {
    ...state,
    list: state.list.concat(payload)
  }
}

It's too difficult to produce a state in a new object instance, especially when you are deeling with a property in a deep object "keyPath", store-renew is just made to fix this, it allow you to return property's "keyPath" in current state and a new property diffrent from old one in an array, for example. you can use like this

import { renew } from 'store-renew'
const reducer = (state, { payload }) => renew(state, `list`, state.list.concat(payload))

or even like below, they has the same effects

import { reduce } from 'store-renew'
const reducer = reduce((state, { payload }) => [`list`, state.list.concat(payload)])

when you need to use dispatch, just as usual.

dispatch({ type: 'add', payload: { id: 1, name: 'King' } })

Package Sidebar

Install

npm i store-renew

Weekly Downloads

4

Version

1.1.3

License

MIT

Unpacked Size

9.65 kB

Total Files

7

Last publish

Collaborators

  • futurer