1const box = []; let cursor = 0;
2function useState(init) {
3 const i = cursor++;
4 if (box[i] === undefined) box[i] = init;
5 return [box[i], (v) => { box[i] = v; }];
6}
7function useToggle(init) {
8 const [on, setOn] = useState(init);
9 return [on, () => setOn(!on)];
10}
11function App() {
12 cursor = 0;
13 const [dark, flipDark] = useToggle(false);
14 const [sound, flipSound] = useToggle(true);
15 console.log("dark:", dark, "| sound:", sound);
16 return [flipDark, flipSound];
17}
18const [flipDark] = App();
19flipDark();
20App();