useToggle()
2022年5月1日小于 1 分钟
useToggle()
Question
It is quite common to see switches and checkboxes in web apps.
Implement useToggle()
to make things easier
function App() {
const [on, toggle] = useToggle()
...
}
Code
export function useToggle(on: boolean): [boolean, () => void] {
// your code here
}
// if you want to try your code on the right panel
// remember to export App() component like below
// export function App() {
// return <div>your app</div>
// }