@gostgroup/use-redux
React hooks for redux integration
Last updated 2 years ago by voronar .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @gostgroup/use-redux 
SYNC missed versions from official npm registry.

Redux in React without "wrapper hell"

About library

React hooks for redux integration.

⚠️ Warning for a usage ⚠️

Use it library carefully because current React Context API has some limitations for outer data subscribtions. More info here: #14110 Provide more ways to bail out inside Hooks.

API

StoreProvider: React.FC<{ store: Store }>

The StoreProvider is just Redux store providing React component.

ReactDom.render(
  <StoreProvider store={store} >
      <AppRootComponent />
  </StoreProvider>,
  appDomNode,
);

useReduxDispatcher(): Redux.Dispatch

The useReduxDispatcher function returns Redux dispatch function for Redux action dispatching.

import { actionCreator } from './actions';

const Component: React.FC = () => {
  const dispatch = useReduxDispatcher();

  const handleClick = React.useCallback(() => {
    dispatch(actionCreator());
  }, []);

  return (
    <button onClick={handleClick}>Push</button>
  );
};

useReduxStateMapper(mapState: (state: T) => R): R

The useReduxStateMapper is like classic mapStateToProps from react-redux library.

const Component: React.FC = () => {
  const { prop1, prop2 } = useReduxStateMapper(
    (state: RootAppState) => ({
      prop1: state.module1.prop1,
      prop2: state.module2.prop2,
    }),
  );

  // ...
};

useReduxStateSelector(stateSelector: (state: T) => R): R

The useReduxStateSelector is more optimized version of useReduxStateMapper because the former subscribes only for selected piece of state changes instead the whole state like the latter.

Selector function for useReduxStateSelector is just regular reselect-like selector.

const Component: React.FC = () => {
  const { module1Prop1, module1Prop2 } = useReduxStateSelector(
    (state: RootAppState) => state.module1),
  );

  // ...
};

Current Tags

  • 1.3.0                                ...           latest (2 years ago)

9 Versions

  • 1.3.0                                ...           2 years ago
  • 1.2.1-alpha.1                                ...           2 years ago
  • 1.1.1-alpha.1                                ...           2 years ago
  • 1.1.0-alpha.1                                ...           2 years ago
  • 1.0.3-alpha.2                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (4)
Dev Dependencies (10)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |