How can I convert the below class with a constructor to a functional component using React Hooks?
class App extends React.Component {
constructor(props) {
super(props);
this.toggleVisibility = this.toggleVisibility.bind(this);
this.handleOnBlur = this.handleOnBlur.bind(this);
}
I saw somewhere online that you can do something like this for the constructor:
const useConstructor(callBack = () => {}) {
const [hasBeenCalled, setHasBeenCalled] = useState(false);
if (hasBeenCalled) return;
callBack();
setHasBeenCalled(true);
}
And then change the class to a function and use it like this:
const App = () => {
useConstructor(() => {});
But I'm not sure what to do with toggleVisibility and handleOnBlur