3.0.19 • Published 4 years ago
@app-elements/with-state v3.0.19
withState
deprecated in favour of useMappedState
Connect a Component to specified global state changes.
Installation
npm install --save @app-elements/with-state
Usage
import withState from '@app-elements/with-state'
// Here is a simple view that expects a `count` value
// form the global state.
const StatefulView = ({ count }) =>
<div>
<h1>Count: {count}</h1>
</div>
// Now we use withState to wrap the StatefulView component
// in a Higher order Component (HoC) that will keep StatefulView
// in sync with changes to `count` in the global state.
const enhance = withState({
// Define the portion of the global state object that
// this Component should be synced with.
mapper: ({ count }) => ({ count })
// equivalent to:
// mapper: state => {
// return { count: state.count }
// }
})
// Since withState is a HoC, it returns a function that expects
// to be called with a Component as its only param.
export default enhance(StatefulView)
Props
Prop | Type | Default | Description |
---|---|---|---|
mapper | Function | None | A function that accepts (state, props) and returns an object |
3.0.19
4 years ago
3.0.18
4 years ago
3.0.17
4 years ago
3.0.16
4 years ago
3.0.13
4 years ago
3.0.14
4 years ago
3.0.15
4 years ago
3.0.12
4 years ago
3.0.11
4 years ago
3.0.10
4 years ago
3.0.9
4 years ago
3.0.8
4 years ago
3.0.7
4 years ago
3.0.6
4 years ago
3.0.5
4 years ago
3.0.4
4 years ago
3.0.3
4 years ago
3.0.2
4 years ago
3.0.1
4 years ago
3.0.0
4 years ago
3.0.0-alpha.0
4 years ago
2.0.21
4 years ago
2.0.20
4 years ago
2.0.19
4 years ago
2.0.18
5 years ago
2.0.17
5 years ago
2.0.16
5 years ago
2.0.15
5 years ago
2.0.14
5 years ago
2.0.13
5 years ago
2.0.12
5 years ago
2.0.11
5 years ago
2.0.10
5 years ago
2.0.8
5 years ago
2.0.7
5 years ago
2.0.6
5 years ago
2.0.5
5 years ago
2.0.4
5 years ago
2.0.3
5 years ago
2.0.2
5 years ago
2.0.1
5 years ago
2.0.0
5 years ago
1.0.10
5 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.7
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.2
6 years ago
1.0.1
6 years ago