Passing callback to useState

#react
#javascript
#performance

Instead of calling the function and passing its returned value to useState , you can pass the function directly. In the first case , the function is executed during each rerender whereas if you pass function directly, its only executed once during the first render , hence a bit of performance boost.

Don't
export const getOrders = () => [
// ...
];

const [orders, setOrders] = useState(getOrders());
Do
export const getOrders = () => [
// ...
];

const [orders, setOrders] = useState(getOrders);

e.target.valueAsNumber

#html
#js

Use e.target.valueAsNumber to automatically return the input value as a number. No need for parseInt(e.target.value) anymore.