React Hooks implementation for Redux that does not suffer from the tearing / "zombie child component" problems.

Official react-redux has now hooks too. You should move to it.
Last updated a year ago by esamatti .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @epeli/redux-hooks 
SYNC missed versions from official npm registry.

⚓ @epeli/redux-hooks

React Hooks implementation for Redux that does not suffer from the tearing / "zombie child component" problems. Read more.

It also implements performance optimizations eg. does not render when the map state function does not produce new value and allows advanced optimizations with memoizing and dependency arrays.

Written in TypeScript so types are baked in and always up to date.

???? Install

npm install @epeli/redux-hooks

???? Usage

import {useMapState, useActionCreators} from "@epeli/redux-hooks";

const ActionCreators = {
    inc() {
        return {type: "INCREMENT"};

function Counter() {
    const count = useMapState(state => state.count);
    const actions = useActionCreators(ActionCreators);

    return <button onClick={actions.inc}>{count}</button>;

Your components must be wrapped with the HooksProvider

import {HooksProvider} from "@epeli/redux-hooks";

    <HooksProvider store={store}>
        <Counter />

Custom provider is required for now because the official react-redux bindings do not use subscriptions and it's impossible to implement Redux hooks without efficiently. Read more about it here.

???? Available hooks

  • useMapState() Renders when returned value differ using Object.is() check
  • useSelect() Renders when returned value differ using shallow equal check
  • useActionCreators() Bind object of action creators to dispatch
  • useDispatch() Returns the plain dispatch-function
  • usePassiveMapState() Like useMapState() but does not subscribe to the store eg. is executed only when the component renders.

Please read the optimizations docs for details when to use these.

TypeScript usage

You can use createHooks() factory to create custom typed version of the hooks

import {createHooks} from "@epeli/redux-hooks";

const AppHooks = createHooks<{foo: string}>();

function Foo() {
    const foo = AppHooks.useMapState(state => state.foo);
    return <div>String: {foo}</div>;


Codesandbox: https://codesandbox.io/s/github/epeli/typescript-redux-todoapp/tree/hooks

Github: https://github.com/epeli/typescript-redux-todoapp/tree/hooks

???? Why yet another Redux Hooks implementation?

All the others I checked had the zombie child bug, poor performance or were missing TypeScript types.

Even the facebookincubator/redux-react-hook one has the zombie bug which is stated in their FAQ. This one guarantees data flow top down like the official react-redux one does.

This also an experiment for the future of the react-redux:


Current Tags

  • 0.6.2                                ...           latest (a year ago)

17 Versions

  • 0.6.2 [deprecated]           ...           a year ago
  • 0.6.1 [deprecated]           ...           a year ago
  • 0.6.0 [deprecated]           ...           a year ago
  • 0.5.5 [deprecated]           ...           a year ago
  • 0.5.4 [deprecated]           ...           a year ago
  • 0.5.3 [deprecated]           ...           a year ago
  • 0.5.2 [deprecated]           ...           a year ago
  • 0.5.1 [deprecated]           ...           a year ago
  • 0.5.0 [deprecated]           ...           a year ago
  • 0.4.0 [deprecated]           ...           a year ago
  • 0.3.2 [deprecated]           ...           a year ago
  • 0.3.1 [deprecated]           ...           a year ago
  • 0.3.0 [deprecated]           ...           a year ago
  • 0.2.0 [deprecated]           ...           a year ago
  • 0.1.2 [deprecated]           ...           a year ago
  • 0.1.1 [deprecated]           ...           a year ago
  • 0.1.0 [deprecated]           ...           a year ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
Dev Dependencies (12)
Dependents (0)

Copyright 2014 - 2016 © taobao.org |