redux-dispatch-hooks
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

redux-dispatch-hooks

Developer friendly dispatch hooks. Brings mapDispatchToProps like experience.

Installation

npm i -S redux-dispatch-hooks

Setup

If you're using react-redux, you can just wrap your app with react-redux Provider and it will work. Otherwise you can use Provider from this lib:

import React from 'react';
import { Provider } from 'redux-dispatch-hooks';
import { createStore } from 'redux';
import { RootComponent } from './your-root-component-path'

const store = createStore(...);

export const App = () => (
  <Provider store={store}>
    <RootComponent>
  </Provider>
);

Usage

import React from "react";
import { useDispatchMap } = from "redux-dispatch-hooks";
import * as actions from "./actions";

const Comment = ({
  onRemove,
  onShare,
}) => {
  return (
    <div>
      SOME COMMENT
      <div onClick={onRemove}>REMOVE</div>
      <div onClick={onShare}>SHARE</div>
    </div>
  )
};

const CommentContainer = () => {
  const dispatchMap = useDispatchMap({
    onRemove
    onShare
  });
  return (
    <Comment
      {...dispatchMap}
    />
  );
}

Readme

Keywords

none

Package Sidebar

Install

npm i redux-dispatch-hooks

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

15.2 kB

Total Files

36

Last publish

Collaborators

  • vaukalak