Separate your state from your components
Last updated 5 years ago by phated .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install sovereign 
SYNC missed versions from official npm registry.


Travis Build Status

Separate your state from your components.

Higher-order component to wrap your stateless React components in a Flux container.


const React = require('react');
const { createContainer } = require('sovereign');

class StatelessComponent extends React.Component {

    return (
      <div {...this.props} />

const StatefulContainer = createContainer(StatelessComponent, {
    return {
      myStore: myFluxStore

    return myFluxStore.getState();

React.render(StatefulContainer, document.getElementById('mount'));


Sovereign exposes a single method createContainer that accepts a React component and a configuration object that allows for fetching data from Flux stores. The configuration object requires 2 functions, getStores and getPropsFromStores.

createContainer(Component, [options]);

This is the method that allows wrapping a stateless component in a stateful container. Any state from the Flux stores may be returned and will be passed as props to the wrapped component. options are optional but if you don't pass them, you probably shouldn't be using this.


Must be a valid React component.


Options requires 2 methods, getStores and getPropsFromStores. Also, 2 methods (listen and unlisten) are optional.


This method must return stores that you would like to listen to. An array or object of stores must be returned. Stores must have listen and unlisten functions available.


This method must return the state from the stores that you would like turned into props. If you are using a library like alt, you could just return myStore.getState() or you can create a subset or aggregate from multiple stores. An object must be returned. This method is called to get initial state as well as updated state upon listen firing.

listen(store, onChange)

This method is called for each store on mount, passing the store and the onChange listener into the method. The default listen method calls store.listen(onChange), but you can override that with this method on options. If listen returns a function, it is passed into the unlisten option (typically this is used as a remover function).

unlisten(store, onChange, remover)

This method is called for each store on unmount, passing the store, onChange listener, and possibly a remover method if it was returned by the listen option. The default unlisten method calls store.unlisten(onChange), but you can override that with this method on options. If the listen option returned a function, this method will receive that function as the last parameter and it can be used as part of you unlisten phase.


Shoutout to alt which had a similar higher-order component as an addon but I didn't completely like the API and wanted this as a standalone library.



Current Tags

  • 0.3.1                                ...           latest (5 years ago)

6 Versions

  • 0.3.1                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
  • 0.0.0                                ...           6 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (7)
Dependents (0)

Copyright 2014 - 2016 © |