From 4ff60b00b398b7b388024b63e30873a1bc7b9882 Mon Sep 17 00:00:00 2001 From: Marcello Lamonaca Date: Tue, 16 Mar 2021 17:41:18 +0100 Subject: [PATCH] useEffect & custom hooks notes --- JavaScript/React/React.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/JavaScript/React/React.md b/JavaScript/React/React.md index ffda712..eeae63c 100644 --- a/JavaScript/React/React.md +++ b/JavaScript/React/React.md @@ -220,3 +220,39 @@ Hook used to create a state object. ```js const [state, setState] = useState(default); ``` + +### `useEffect` + +Hook used to trigger an action on each reder of the component. + +```js +useEffect(() => + // introduce side effect of the render + + return () => {/* clean up side effect */} +); +``` + +### Custom Hooks + +```js +// hook definitions +const useCutomHook = () => { + // eventual state definitions + + // eventual function definitions + + // ... + + return { obj1, obj2, ... }; +} + +const Component(){ + // retrieve elements from the hook + const { + obj1, + obj2, + ... + } = useCustomHook(); +} +```