Skip to content

Latest commit

 

History

History
57 lines (40 loc) · 1.45 KB

README.md

File metadata and controls

57 lines (40 loc) · 1.45 KB

Redux-Bundler Hook

CircleCI

React.js bindings to Henrik Joreteg's redux-bundler.

See redux-bundler documentation at https://reduxbundler.com/

Installation

npm install redux-bundler-hook

Usage

wrap your React app with a provider

import { hydrate } from 'react-dom'
import { ReduxBundlerProvider } from 'redux-bundler-hook'

import createStore from '../bundles'

const store = createStore()

hydrate(
  <ReduxBundlerProvider store={store}>
    <App />
  </ReduxBundlerProvider>,
  document.getElementById('root')
)

use the hook in your components

import { useConnect } from 'redux-bundler-hook'

import AppLayout from './AppLayout'

export default function App() {
  const {
    route: { component: RoutedComponent },
    colorScheme,
    doSetColorScheme,
  } = useConnect('selectRoute', 'selectColorScheme', 'doSetColorScheme')

  return (
    <AppLayout>
      <RoutedComponent colorScheme={colorScheme} onSetColorScheme={doSetColorScheme} />
    </AppLayout>
  )
}

In cases you need a store itself down your component tree, this package also exports useReduxBundlerStore hook that will return the store.