JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q33805F
  • License MIT

Package Exports

  • microstate

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (microstate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

microstate

Hyperminimal, co-located and composable state management for React and React-like libraries.

js-standard-style

Usage

microstate has essentially the same API as Redux. First, wrap the part of your app you want to be stateful with a Provider. There's no need to define reducers or actions: that's all handled at the component level.

// App.js
import { Provider } from 'microstate'

export default props => (
  <div>
    <Provider>
      <h1>My App</h1>
    </Provider>
  </div>
)

// index.js
render(<App/>, root)

Next, hook up a child component to state using connect():

// Component.js
import { connect } from 'microstate'

export default connect(
  {
    message: 'Hello!'
  },
  state => ({
    output: state.message
  }),
  dispatch => ({
    greet: name => dispatch({
      message: `Hello ${name}!`
    })
  })
)(props => (
  <div>
    <button onClick={e => props.greet('Eric')}>Greet</button>
    <div>{props.output}</div>
  </div>
))

// App.js
import { Provider } from 'microstate'
import Component from './Component.js'

export default props => (
  <div>
    <Provider>
      <Component/>
    </Provider>
  </div>
)

// index.js
render(<App/>, root)

Example

To run the example, clone this repo, then:

# move into example dir
cd srraf/example
# install deps
npm i
# compile JS
npm run js:build # or js:watch
# serve index.html and update with changes
live-server 

MIT License