Custom Hooks in TypeScript

import { useState } from "react";export const useToggle = (): [boolean, () => void] => {// rest of the code};
// inside useToggleconst [toggleOn, setToggleOn] = useState<boolean>(false);const updateToggle = () => {  setToggleOn((prevToggleOn) => !prevToggleOn);};return [toggleOn, updateToggle];
import { useToggle } from "./useToggle";export default function App() {   const [toggleOn, updateToggle] = useToggle();   return (    <div className="App">
<button
onClick={updateToggle}>
{toggleOn ? "ON" : "OFF"}
</button>
</div>
);}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store