-
Notifications
You must be signed in to change notification settings - Fork 0
API
alevnyacow edited this page Mar 24, 2022
·
1 revision
Generates a tuple of two hooks:
- first hook is a React variable generator
- second hook can be used to rewrite a whole variable (you don't need this most likely)
function createUseSharedVariable<T extends object>(initialState: T):
readonly [ReactVariableHook<T>, ReactVariableRewriteHook<T>]
Take a look at the Types section to get description of ReactVariableHook
and ReactVariableRewriteHook
types.
const [useTimer, useWholeTimerRewrite] = createUseSharedVariable({
ticks: 0
});
Describes a hook which returns a shared React variable. It's a generic type taking a type of an output React variable. This hook takes one parameter (optional rerenderOnChange
boolean flag, set to true by default) can be used to prevent a rerender on React variable changes.
type ReactVariableHook<T> = (rerenderOnChange?: boolean) => T;
Describes a hook can be used to rewrite a whole React variable. It needs a generator
to work. The generator is a function which takes previous variable state and returns target variable state. Pretty like a setState
function, yeah.
type ReactVariableRewriteHook<T> = () => (
generator: (oldState: T) => T
) => void;