This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {makeAutoObservable} from "mobx"; | |
| import React, {type Context, createContext, type FC, type PropsWithChildren, useRef} from "react"; | |
| export function createContexts<T extends Record<string, () => any>>(factories: T) { | |
| type Keys = keyof T & string; | |
| type Instances = { [K in Keys]: ReturnType<T[K]> }; | |
| const out = {} as { | |
| [K in Keys as `${K}Provider`]: FC<PropsWithChildren<{}>> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {makeAutoObservable} from "mobx"; | |
| import {observer} from "mobx-react-lite"; | |
| class CounterState { | |
| count = 0 | |
| constructor() { | |
| makeAutoObservable(this, {}, {autoBind: true}) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {useTrackedState, useAutoEffect} from './useAutoEffect.ts' | |
| // example | |
| const Counter = () => { | |
| const [count, setCount] = useTrackedState(0); | |
| useAutoEffect(() => { | |
| console.log("Called one time") | |
| }) |