Skip to content

Coder-JJ/rematch-immer-combine-persist

Repository files navigation

rematch-immer-combine-persist

Why rematch-immer-combine-persist?

  • Combine immer and persist

  • Can use with @rematch/loading (@rematch/immer can't)

CHANGELOG

Docs

Install

npm i rematch-immer-combine-persist -S

Options

interface ImmerOptions {
  blacklist?: string[]
  whitelist?: string[]
}

interface PersistOptions<S, RS, HSS, ESS> {
  persistConfig?: Partial<PersistConfig<S, RS, HSS, ESS>>
  persistorOptions?: PersistorOptions | null
  callback?: () => any
}

interface PluginOptions<S, RS, HSS, ESS> {
  immerOptions?: ImmerOptions
  persistOptions?: PersistOptions<S, RS, HSS, ESS>
}

Usage

  • Basic usage

    // store.js
    import { init } from '@rematch/core'
    import immerCombinePersist from 'rematch-immer-combine-persist'
    import * as models from './models'
    
    const store = init({
      models,
      plugins: [
        immerCombinePersist()
      ]
    })
    
    export default store
    // index.js
    import React from 'react'
    import ReactDOM from 'react-dom'
    import { Provider } from 'react-redux'
    import { PersistGate } from 'redux-persist/integration/react'
    import { getPersistor } from 'rematch-immer-combine-persist'
    import store from './store'
    import App from './App'
    
    const persistor = getPersistor()
    
    ReactDOM.render(
      <Provider store={store}>
        <PersistGate persistor={persistor}>
          <App />
        </PersistGate>
      </Provider>,
      document.getElementById('root')
    )
  • Use with @rematch/loading

    // store.js
    import { init } from '@rematch/core'
    import loading '@rematch/loading'
    import immerCombinePersist from 'rematch-immer-combine-persist'
    import * as models from './models'
    
    const store = init({
      models,
      plugins: [
        loading(),
        immerCombinePersist({
          immerOptions: {
            blacklist: ['loading']
          }
        })
      ]
    })
    
    export default store

About

rematch plugin combine immer and persist

Resources

License

Stars

Watchers

Forks

Packages

No packages published