atualizar a matriz usestate
<body>
<div id="root"></div>
<script>
const { useState } = React;
const App = () => {
const [myArray, updateMyArray] = useState([]);
const onClick = () => {
updateMyArray( arr => [...arr, `${arr.length}`]);
};
return [
<input type="button" onClick={ onClick } value="Update" />,
<div>{myArray.map( e =>
<div>{ e }</div>
)}
</div>
];
}
ReactDOM.render(
<App />,
document.getElementById("root")
);
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.1/umd/react-dom.production.min.js"></script>
</body>
King Bean