This package has been deprecated

Author message:

This package is deprecated, headless React component (preferably hooks) + react-redux is a superior solution

redux-bind-store
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

redux-bind-store Build Status

Install

npm i --save redux-bind-store

Usage

import { bindStore } from 'redux-bind-store'

// redux store
const store = createStore(reducer);

// bind to given store
const { getState, dispatch, connect } = bindStore(store);

// work with global getState and dispatch
const state = getState();
dispatch(someAction());

// connect to store changes with cache selectors
connect(state => {
    isLoggedIn: isLoggedInSelector(state),
}, ({ newProps, dispatch }) => {
    const { isLoggedIn } = newProps;
    if (!isLoggedIn) {
        // logged out case, skip
        return;
    }
    dispatch(someActionWhenLoggedIn());
});

API

bindStore

function bindStore(store)

bindStore Params

  • store: store - redux store

bindStore Returns

bindStore returns an object with following properties:

  • getState: () => state - redux getState method binded to the store
  • dispatch: (action) => void - redux dispatch method binded to the store
  • subscribe: (listener) => () => void - redux subscribe method binded to the store
  • connect: () => () => void - connect to store updates

connect

function connect(mapStateToProps, propsChangedHander)

connect Params

  • mapStateToProps: state => object - map the state to a props object
  • propsChangedHandler: event => void - callback for the props changed event, the handler callback will be called with event object contains:
    • newProps: object - current mapStateToProps result
    • prevProps: object - previous mapStateToProps result, null for the first call
    • getState: () => state - redux getState method binded to the store
    • dispatch: (action) => void - redux dispatch method binded to the store

connect Returns

connect returns an unsubscribe method - the one returned by store.subscribe - which will disconnect the propsChangedHander when called.

Readme

Keywords

Package Sidebar

Install

npm i redux-bind-store

Weekly Downloads

1

Version

0.2.1

License

MIT

Unpacked Size

11 kB

Total Files

10

Last publish

Collaborators

  • rocwind