Skip to content

Wedux: v0.0.11

Choose a tag to compare

@ItsJonQ ItsJonQ released this 13 Dec 15:15
· 6 commits to master since this release

createUniqueStore

This is a special feature that allows you to create stores (with associating Provider/connect components) with guaranteed unique store keys. This is important if you plan on creating multiple nested stores. This is especially good for libraries, as it guarantees that the library's Wedux components don't clash with the integrated application Wedux components.

createUniqueStore(reducer, enhancer, namespace)

Argument Type Description
reducer Object/Function Reducer/initialState for the store.
enhancer Object Store enhancer, like applyMiddleware.
namespace string A custom namespace for the store (context). It will still be unique.

Example

import {createUniqueStore} from '@helpscout/wedux'

const libStore = createUniqueStore()
const appStore = createUniqueStore()

const Bob = ({makeBurger}) => <button onClick={makeBurger}>Make Burger</button>

const makeBurger = store => {
  return {
    didMakeBurgers: !store.didMakeBurgers,
  }
}

const ConnectedBob = libStore.connect(
  null,
  {makeBurger},
)(Bob)

class App extends React.Component {
  render() {
    return (
      <appStore.Provider>
        <div>
          ...
          <libStore.Provider>
            <ConnectedBob />
          </libStore.Provider>
          ...
        </div>
      </appStore.Provider>
    )
  }
}