mobxjs / mobxjs/mobx-react-devtools

App works, but DevTools gives error "TypeError: this.todos is undefined"

Open
#75 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.2k
Forks
45
PR merge metrics
No merged PRs in 30d

Description

The setup is simple. React with MobX and TypeScript along with MobX DevTools. The app is pretty much a copy paste of the 10 min todo introduction of MobX. The app works, but once I try to inspect the content of my store with DevTools I receive an error:

image

The code for the store is as follows:

export default class ObservableTodoStore {
    @observable 
    todos: any[] = [];
    @observable 
    pendingRequests: number = 0;

    constructor() {
        autorun(() => console.log(this.report));
    }

    @computed 
    get completedTodosCount() {
        return this.todos.filter(
            (todo: any) => todo.completed === true
        ).length;
    }

    @computed 
    get report() {
        if (this.todos.length === 0) {
            return '<none>';
        }
        return `Next todo: "${this.todos[0].task}". ` +
            `Progress: ${this.completedTodosCount}/${this.todos.length}`;
    }

    @action
    addTodo(task: any) {
        this.todos.push({
            task: task,
            completed: false,
            assignee: null
        });
    }
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ObservableTodoStore code in the issue and reproduce the failure while inspecting the store in MobX DevTools. Trace why DevTools reports that this.todos is undefined; done means the provided store can be inspected without the TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.