React Hooks append state
setTheArray(currentArray => [...currentArray, newElement])setTheArray([...theArray, newElement]);const {useState, useCallback} = React;
function Example() {
const [theArray, setTheArray] = useState([]);
const addEntryClick = () => {
setTheArray([...theArray, `Entry ${theArray.length}`]);
};
return [
<input type="button" onClick={addEntryClick} value="Add" />,
<div>{theArray.map(entry =>
<div>{entry}</div>
)}
</div>
];
}
ReactDOM.render(
<Example />,
document.getElementById("root")
);
Also in JavaScript:
- node js how to basic auth to specific urk
- js array from
- css and js on flask
- pdf.js change background color
- what does componentDidCatch do in react
- javascript números pegar apenas o decimal
- using javascript to validation email before next field
- dropdown validation using jquery
- how to format json file in vs code
- multiline textinput in react native
- react return action in a function
- javascript remove duplicate strings from array
- angular material theme colors
- js return a promise
- multiple case switch javascript
- settimeout in a for loop javascript
- bigint type js
- how to add button react native app.js
- javascript convert to boolean
- Write a regular expression to validate phone number in XXX-XXX-XXXX format?
- onchange value in hidden input
- javascript max safe integer
- if javascript
- mdn golang