MCPcopy
hub / github.com/mobxjs/mobx / observer

Function observer

packages/mobx-react/src/observer.tsx:12–32  ·  view source on GitHub ↗
(component: T, context?: ClassDecoratorContext)

Source from the content-addressed store, hash-verified

10export function observer<T extends IReactComponent>(component: T, context: ClassDecoratorContext): void
11export function observer<T extends IReactComponent>(component: T): T
12export function observer<T extends IReactComponent>(component: T, context?: ClassDecoratorContext): T {
13 if (context && context.kind !== "class") {
14 throw new Error("The @observer decorator can be used on classes only")
15 }
16 if (component["isMobxInjector"] === true) {
17 console.warn(
18 "Mobx observer: You are trying to use `observer` on a component that already has `inject`. Please apply `observer` before applying `inject`"
19 )
20 }
21
22 if (
23 Object.prototype.isPrototypeOf.call(React.Component, component) ||
24 Object.prototype.isPrototypeOf.call(React.PureComponent, component)
25 ) {
26 // Class component
27 return makeClassComponentObserver(component as React.ComponentClass<any, any>) as T
28 } else {
29 // Function component
30 return observerLite(component as React.FunctionComponent<any>) as T
31 }
32}

Callers 14

createStoreInjectorFunction · 0.90
doTestFunction · 0.90
hooks.test.tsxFile · 0.90
observer.test.tsxFile · 0.90
context.test.tsxFile · 0.90
inject.test.tsxFile · 0.90
connectFunction · 0.90
misc.test.tsxFile · 0.90
stateless.test.tsxFile · 0.90
issue21.test.tsxFile · 0.90
compile-ts.tsxFile · 0.90

Calls 1

Tested by 2

doTestFunction · 0.72
connectFunction · 0.72