Last active
July 3, 2017 22:54
-
-
Save jamiebuilds/35d86c4dac146e1e84c3dbd3d37e3de1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function increment(props, state) { | |
return { | |
value: state.value + props.step, | |
}; | |
} | |
function decrement(props, state) { | |
return { | |
value: state.value - props.step, | |
}; | |
} | |
function Counter(props: { step: number }, state = { value: 0 }, updater) { | |
return ( | |
<div> | |
<button onClick={updater(increment)}>+</button> | |
<h1>{state.value}</h1> | |
<button onClick={updater(decrement)}>-</button> | |
</div> | |
); | |
} | |
ReactDOM.render( | |
<Counter step={5}/>, | |
document.getElementById('root') | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let increment = (props, state) => ({ | |
value: state.value + props.step, | |
}) | |
let decrement = (props, state) => ({ | |
value: state.value - props.step, | |
}) | |
let Counter = (props: { step: number }, state = { value: 0 }, updater) => ( | |
<div> | |
<button onClick={updater(increment)}>+</button> | |
<h1>{state.value}</h1> | |
<button onClick={updater(decrement)}>-</button> | |
</div> | |
) | |
ReactDOM.render( | |
<Counter step={5}/>, | |
document.getElementById('root') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment