-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
COMP: docsImprovements or additions to documentationImprovements or additions to documentationVERSION: upcoming major
Description
Suggestion
V2 code:
/**
* Stores a value which is retained for the lifetime of the component. Subsequent calls to
* `useConstant` will always return the first value given.
*
* If the value is a function, the function is invoked once to calculate the actual value.
*
* @public
*/
export const useConstant = <T>(value: (() => T) | T): T => {
const { val, set } = useSequentialScope<T>();
if (val != null) {
return val;
}
// Note: We are not using `invoke` here because we don't want to clear the context
value = isFunction(value) && !isQwikComponent(value) ? value() : value;
return set(value as T);
};Note: in V1 it's marked as deprecated but not in V2.
Metadata
Metadata
Assignees
Labels
COMP: docsImprovements or additions to documentationImprovements or additions to documentationVERSION: upcoming major
Type
Projects
Status
Backlog