The type of value the hook returns
= void Optional type of runtime params passed to the hook
Configuration with onUse + optional memoize/name
A hook function you can call in components, optionally with params
const useMyTimer = createUseHook({
name: "useMyTimer",
onUse: () => {
const elapsed = useRef(0);
useTick(dt => { elapsed.current += dt; });
return { getElapsed: () => elapsed.current };
}
});
const useMoveSpeed = createUseHook<number, [{ baseSpeed: number }]>({
name: "useMoveSpeed",
onUse: (fiber, global, { baseSpeed }) => {
const speed = useRef(baseSpeed);
useTick(dt => { speed.current += 0.1 * dt; });
return speed.current;
}
});
// usage
const speed = useMoveSpeed({ baseSpeed: 200 });
Factory to create custom, reusable hooks for Kayla that can accept runtime parameters.
The returned hook can be called with optional params that are passed to
onUse. By default, the result is memoized (runsonUseonly once per entity).