From 604457ccdf4adcbad93d06439112535f3c0e98b2 Mon Sep 17 00:00:00 2001 From: Ian K Smith Date: Fri, 21 Oct 2022 10:20:35 -0600 Subject: [PATCH] Update docs --- docs/use-callback-const.md | 15 ++++++++++++++- docs/use-callback-ref.md | 26 +++++++++++++++++++++++++- docs/use-value-ref.md | 10 +++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/docs/use-callback-const.md b/docs/use-callback-const.md index 1d12202..996ca25 100644 --- a/docs/use-callback-const.md +++ b/docs/use-callback-const.md @@ -1,3 +1,16 @@ # `useCallbackConst` -Documentation coming soon... +Creates a callback with a constant value over the lifecycle of a component. + +## Example + +```tsx +const immutableCallback = useCallbackConst(() => { + console.log( + `I don't have any local state dependencies + and I won't trigger unncessary re-renders.` + ); +}); + + +``` diff --git a/docs/use-callback-ref.md b/docs/use-callback-ref.md index b6bc1d1..c69d3c8 100644 --- a/docs/use-callback-ref.md +++ b/docs/use-callback-ref.md @@ -1,3 +1,27 @@ # `useCallbackRef` -Documentation coming soon... +Converts a callback to a ref to avoid triggering re-renders when passed as a +prop or avoid re-executing effects when passed as a dependency. + +Returns a new callback with a constant value over the lifecycle of a component. + +## Example + +```tsx +const [state, setState] = useState(0); + +const logState = useCallbackRef(() => { + console.log('state:', state); +}); + +useEffect(() => { + logState(); + // => "state: 1" + // => "state: 2" + // => "state: 3" + // => "state: 4" + // => ... +}, [state]); + + +``` diff --git a/docs/use-value-ref.md b/docs/use-value-ref.md index 0c7c944..52ea9c5 100644 --- a/docs/use-value-ref.md +++ b/docs/use-value-ref.md @@ -1,3 +1,11 @@ # `useValueRef` -Documentation coming soon... +Converts a given value to a ref to avoid triggering re-renders when passed as a +prop or avoid re-executing effects when passed as a dependency. + +Returns a ref object with a constant value over the lifecycle of a component. + +## Example + +Example coming soon... +