1.0.3 • Published 7 years ago

local-state-hoc v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Local State Hoc

import {connect} from 'react-redux'
import {withLocalState} from 'local-state-hoc'

const View = ({ updateIndex, index }) => (
  <div>
    <button onClick={updateIndex} />
    <p>{index}</p>
  </div>
)

const defaultLocalState = {
  index: 0
}

const mapStateToProps = (_, { localState, setLocalState }) => ({
  updateIndex: () => setLocalState({ index: localState.index + 1 }),
  index: localState.index
})

export default withLocalState(connect(mapStateToProps)(View), defaultLocalState)