1.0.0 • Published 7 years ago

react-with-state v1.0.0

Weekly downloads
5
License
ISC
Repository
github
Last release
7 years ago

react-with-state

Higher-order component abstraction for adding state management to a dumb component.

provides these props:

  • state
  • setState

try it on codepen

import React from 'react'
import {render} from 'react-dom'

import withState from '../../src'

const Counter = ({state, setState}) =>
  <div>
    {state.count}
    <button onClick={() => setState({count: state.count + 1})}>
      Increment
    </button>
  </div>

const manageCounterState = withState({count: 0})
const ManagedCounter = manageCounterState(Counter)

render(<ManagedCounter />, document.querySelector('#demo'))