Skip to content

Commit

Permalink
doesn't support pure component
Browse files Browse the repository at this point in the history
  • Loading branch information
jzhan-canva committed May 29, 2024
1 parent 8b0bb62 commit 1840137
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
22 changes: 1 addition & 21 deletions packages/mobx-react/__tests__/observer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ test("it rerenders correctly if some props are non-observables - 2", () => {
let odata = observable({ x: 1 })

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

test("use PureComponent", () => {
const msg: Array<any> = []
const baseWarn = console.warn
console.warn = m => msg.push(m)

try {
observer(
class X extends React.PureComponent {
render() {
return <div />
}
}
)

expect(msg).toEqual([])
} finally {
console.warn = baseWarn
}
})

test("static on function components are hoisted", () => {
const Comp = () => <div />
Comp.foo = 3
Expand Down
2 changes: 2 additions & 0 deletions packages/mobx-react/src/observerClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export function makeClassComponentObserver(
"It is not allowed to use shouldComponentUpdate in observer based components."
)
}
} else {
throw new Error("It is not allowed to use observer on PureComponent.")
}

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

0 comments on commit 1840137

Please sign in to comment.