Skip to content

Uncaught Error: [mobx] Cannot obtain atom from undefined #92

@corysimmons

Description

@corysimmons
import React from 'react'
import DevTools from 'mobx-react-devtools'
import { observable } from 'mobx'
import { observer } from 'mobx-react'

@observer
class App extends React.Component {
  @observable count = 0

  inc = () => {
    this.count++
  }

  dec = () => {
    this.count--
  }

  render() {
    return (
      <div>
        <h1>{this.count}</h1>
        <button onClick={() => this.inc()}>+</button>
        <button onClick={() => this.dec()}>-</button>
        <DevTools />
      </div>
    )
  }
}

export default App

...using rewire mobx.. It seems to work. If I click the last icon, I get:

image

The undefined looks a bit worrisome, but then I click the middle icon and I get this:

image

What am I messing up? I'm following the Mobx course on Egghead. It's probably a bit dated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions