1.0.1 • Published 4 years ago

react-redux-typed-hooks v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

react-redux-typed-hooks

Typed hooks for react-redux. Read more about it here.

Usage:

  • Define your store and store event types (store events are objects which are passed to the dispatch function).
  • Get the hooks from the factory provided by this package, and export them.
  • Enjoy.

Example:

// store/index.ts

import { createStore, combineReducers } from 'redux'
import getHooks from 'react-redux-typed-hooks'

import fruits, { FruitStore, FruitStoreEvent } from './fruits'
import others, { OtherStore, OtherStoreEvent } from './others'

type Event = FruitStoreEvent | OtherStoreEvent

interface Store {
  fruits: FruitStore;
  others: OtherStore;
}

export const { useSelector, useDispatch } = getHooks<Store, Event>()

export default createStore(
  combineReducers({
    fruits,
    others
  })
)

In your component files:

// view/component.tsx

// import { useDispatch, useSelector } from 'react-redux' // WRONG
import { useSelector, useDispatch } from '../store'
1.0.1

4 years ago

1.0.0

4 years ago