Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement