is it possible to use a function
as my React Component\'s state ?
example code here:
// typescript
type OoopsFunction = () => void;
exp
It is possible to set a function in state using hooks, but because state can be initialized and updated with a function that returns the initial state or the updated state, you need to supply a function that in turn returns the function you want to put in state.
const { useState } = React;
function App() {
const [ooops, setOoops] = useState(() => () => console.log("default ooops"));
return (
);
}
ReactDOM.render( , document.getElementById("root"));