Skip to content

Instantly share code, notes, and snippets.

@denisos
Created December 22, 2021 21:08
Show Gist options
  • Save denisos/239b257beed20e61728a15a521069f51 to your computer and use it in GitHub Desktop.
Save denisos/239b257beed20e61728a15a521069f51 to your computer and use it in GitHub Desktop.
// 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