I\'d like to know how to toggle a boolean state of a react component. For instance:
I have boolean state check in the constructor of my component:
const
-
Here's an example using hooks (requires React >= 16.8.0)
// import React, { useState } from 'react';
const { useState } = React;
function App() {
const [checked, setChecked] = useState(false);
const toggleChecked = () => setChecked(value => !value);
return (
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(, rootElement);
- 热议问题