diff --git a/apis/stardust/api-spec/spec.json b/apis/stardust/api-spec/spec.json index 12597d3ad..e3b03ba73 100644 --- a/apis/stardust/api-spec/spec.json +++ b/apis/stardust/api-spec/spec.json @@ -154,6 +154,20 @@ "import { useMemo } from '@nebula.js/stardust';\n// ...\nconst v = useMemo(() => {\n return doSomeHeavyCalculation();\n}), []);" ] }, + "useRef": { + "description": "Creates a reference to a value not needed for rendering\n\nWhile Nebula does not have a virtual DOM, it is still useful\nto have a reference to an object that is retained across\nrenders and in it self does not trigger a render.", + "kind": "function", + "params": [ + { + "name": "initialValue", + "description": "The initial value.", + "type": "any" + } + ], + "examples": [ + "import { useRef } from '@nebula.js/stardust';\n// ...\n// initiate with simple value\nconst timesRendered = useRef(0);\n\nuseEffect(() => {\n render(layout);\n // increments the render counter, a useState would trigger another render\n timesRendered.current += 1;\n},[layout]);" + ] + }, "usePromise": { "description": "Runs a callback function when a dependent changes.\n\nUseful for async operations that otherwise cause no side effects.\nDo not add for example listeners withing the callback as there is no teardown function.", "templates": [ diff --git a/apis/stardust/types/index.d.ts b/apis/stardust/types/index.d.ts index a431a035a..27f975940 100644 --- a/apis/stardust/types/index.d.ts +++ b/apis/stardust/types/index.d.ts @@ -41,6 +41,16 @@ export function useEffect(effect: stardust.EffectCallback, deps?: any[]): void; */ export function useMemo(factory: ()=>T, deps: any[]): T; +/** + * Creates a reference to a value not needed for rendering + * + * While Nebula does not have a virtual DOM, it is still useful + * to have a reference to an object that is retained across + * renders and in it self does not trigger a render. + * @param initialValue The initial value. + */ +export function useRef(initialValue: any): void; + /** * Runs a callback function when a dependent changes. *