Skip to content

useRedux

Александр edited this page Jan 17, 2023 · 1 revision
export function useRedux<T>(config: T): {
  [key in keyof T]: ReturnType<T[key]>
}

Accepts a config object of the form { key: selector }.

Subscribes to the change of the store and returns an object of the form { key: value_from_selector }.

import { afc, useRedux } from 'react-afc'
import { selectName, selectAge } from './personSlice'

function Component(props) {
  const store = useRedux({
    name: selectName,
    age: selectAge,
    count: s => s.count.value
  })

  return () => (
    <p>Name: {store.name}; Age: {store.age}; Count {store.count}</p>
  )
}

export default afc(Component)
Clone this wiki locally