A Pen by Etienne Deladonchamps on CodePen.
Created
September 10, 2017 09:40
-
-
Save etienne-dldc/33adc1999123e5361f7c33462e0f3b2b to your computer and use it in GitHub Desktop.
07 - Multiple Counters v2 - React JSX Clean
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
var body = document.body; | |
// State | |
var counters = [0, 0, 0]; | |
// Render | |
function render() { | |
return ( | |
<div> | |
<button | |
onClick={function() { | |
counters.push(0); | |
renderWithReact(); | |
}} | |
> | |
Add counter | |
</button> | |
<br /> | |
<div> | |
{counters.map(function(value, index) { | |
return ( | |
<div> | |
<span>{value}</span> | |
{value > 0 && | |
<button | |
onClick={function() { | |
counters[index] = value - 1; | |
renderWithReact(); | |
}} | |
> | |
- | |
</button>} | |
{value < 10 && | |
<button | |
onClick={function() { | |
counters[index] = value + 1; | |
renderWithReact(); | |
}} | |
> | |
+ | |
</button>} | |
</div> | |
); | |
})} | |
</div> | |
</div> | |
); | |
} | |
function renderWithReact() { | |
ReactDOM.render(render(), body); | |
} | |
// Initial render | |
renderWithReact(); |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react-dom.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment