Skip to content

Commit 1840137

Browse files
committed
doesn't support pure component
1 parent 8b0bb62 commit 1840137

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

packages/mobx-react/__tests__/observer.test.tsx

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ test("it rerenders correctly if some props are non-observables - 2", () => {
563563
let odata = observable({ x: 1 })
564564

565565
@observer
566-
class Component extends React.PureComponent<any, any> {
566+
class Component extends React.Component<any, any> {
567567
@computed
568568
get computed() {
569569
return this.props.data.y // should recompute, since props.data is changed
@@ -756,26 +756,6 @@ describe("use Observer inject and render sugar should work ", () => {
756756
})
757757
})
758758

759-
test("use PureComponent", () => {
760-
const msg: Array<any> = []
761-
const baseWarn = console.warn
762-
console.warn = m => msg.push(m)
763-
764-
try {
765-
observer(
766-
class X extends React.PureComponent {
767-
render() {
768-
return <div />
769-
}
770-
}
771-
)
772-
773-
expect(msg).toEqual([])
774-
} finally {
775-
console.warn = baseWarn
776-
}
777-
})
778-
779759
test("static on function components are hoisted", () => {
780760
const Comp = () => <div />
781761
Comp.foo = 3

packages/mobx-react/src/observerClass.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ export function makeClassComponentObserver(
9797
"It is not allowed to use shouldComponentUpdate in observer based components."
9898
)
9999
}
100+
} else {
101+
throw new Error("It is not allowed to use observer on PureComponent.")
100102
}
101103

102104
// this.props and this.state are made observable, just to make sure @computed fields that

0 commit comments

Comments
 (0)