UNPKG

lobx-react

Version:

Lightweight React bindings for lobx based on React 16.8+ and Hooks

31 lines (19 loc) 1.33 kB
# lobx-react **You need React version 16.8.0 and above** ## API reference ⚒ ### **`observer<P>(baseComponent: Component<P>, options?: ObserverOptions): Component<P>`** ```ts interface ObserverOptions { // Pass true to wrap the inner component with React.forwardRef. // It's false by the default. forwardRef?: boolean graph?: Graph } ``` The observer converts a component into a reactive component, which tracks which observables are used automatically and re-renders the component when one of these values changes. ### **`useObservable<T>(sourceOrInitializer: T | (() => T)): T`** The useObservable hook can be used to turn any set of values into an observable object that has a stable reference (the same object is returned every time from the hook). You can either pass in a default value or a initializer function that will run once and the value returned will be the default. ### **`<Observer>{renderFn}</Observer>`** Is a React component, which applies observer to an anonymous region in your component. ### **`enableStaticRendering(enable: true)`** Call `enableStaticRendering(true)` when running in an SSR environment, in which `observer` wrapped components should never re-render, but cleanup after the first rendering automatically. Use `isUsingStaticRendering()` to inspect the current setting.