Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. const initialState = { width: 15 };
  2.  
  3. const reducer = (state, newState) => ({
  4. ...state,
  5. width: newState.width
  6. })
  7.  
  8. const Bar = () => {
  9. const [state, setState] = useReducer(reducer, initialState)
  10. return <>
  11. <div style={{ background: 'teal', height: '30px', width: state.width }}></div>
  12. <div style={{marginTop: '3rem'}}>
  13. <button onClick={() => setState({width: 100})}>Increase bar size</button>
  14. <button onClick={() => setState({width: 3})}>Decrease bar size</button>
  15. </div>
  16. </>
  17. }
  18.  
  19. ReactDOM.render(Bar)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement