Skip to content

Instantly share code, notes, and snippets.

@ohansemmanuel
Last active April 13, 2019 08:53
Show Gist options
  • Select an option

  • Save ohansemmanuel/dad09e38e5060f0c8a5db5b8b85dc9c8 to your computer and use it in GitHub Desktop.

Select an option

Save ohansemmanuel/dad09e38e5060f0c8a5db5b8b85dc9c8 to your computer and use it in GitHub Desktop.
const initialState = { width: 15 };
const reducer = (state, newState) => ({
...state,
width: newState.width
})
const Bar = () => {
const [state, setState] = useReducer(reducer, initialState)
return <>
<div style={{ background: 'teal', height: '30px', width: state.width }}></div>
<div style={{marginTop: '3rem'}}>
<button onClick={() => setState({width: 100})}>Increase bar size</button>
<button onClick={() => setState({width: 3})}>Decrease bar size</button>
</div>
</>
}
ReactDOM.render(Bar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment