import { getCurrentInstance } from "../ui/createFunctionalComponent"; import { Ref } from "../data/Ref"; let key: number = 0; export function useState(defaultValue?: T): Ref { let instance = getCurrentInstance(); let storeKey = "_state" + ++key; instance.setState({ [storeKey]: defaultValue, }); return new Ref({ get: (): T => instance.state[storeKey], set: (value: T): boolean => { instance.setState({ [storeKey]: value }); return true; }, }); }