Created
December 22, 2021 21:08
-
-
Save denisos/239b257beed20e61728a15a521069f51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example of common basic custom hooks pattern | |
// | |
export default function useCounter() { | |
const [counter, setCounter] = useState(0); | |
useEffect(() => { | |
// do something e.g. initialze things | |
}, []) | |
// this is the api for the hook | |
return { | |
counter, // state property which when changed will trigger rerenders | |
setCounter // example of api | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment