Skip to content

Instantly share code, notes, and snippets.

@leahpjoyce
Created September 6, 2018 19:25
Show Gist options
  • Save leahpjoyce/03bcba1888c1ed5003d5c1ff8f26c981 to your computer and use it in GitHub Desktop.
Save leahpjoyce/03bcba1888c1ed5003d5c1ff8f26c981 to your computer and use it in GitHub Desktop.
Passing Data
<div id="root"></div>
function ClickyButtons({numberOfButtons, onSelection}) {
const makeButton = v => <button key={v} id={v} onClick={event => onSelection(event.target.id)}>{v}</button>;
return <div>
{_.range(1, numberOfButtons + 1).map(makeButton)}
</div>;
}
ReactDOM.render(<ClickyButtons numberOfButtons={99} onSelection={console.log}/>,
document.getElementById('root')
);
<script src="//unpkg.com/react/umd/react.development.js"></script>
<script src="//unpkg.com/react-dom/umd/react-dom.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment