My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

mobx store data comming undefined in its method using Typescript

Default profile photo
Anonymous
·Jul 8, 2019

Here is my store

import { action, computed, observable } from "mobx";

class TaskStorageJson {
    @observable public taskStorage = {};

    @action public addNewTaskStorageJson(storageJson: Object[]) {
        console.log("this.taskStorage", this.taskStorage); // output - undefined
        // this.taskStorage =  storageJson;
    }
    @action getTaskStorage = () => this.taskStorage;
}

const store = new TaskStorageJson();
export default store;

here in addNewTaskStorageJson method in the console.log , its comming undefined.

Dependencies I am using

  • "mobx": "^5.11.0",
  • "mobx-react": "^6.1.1",
  • "polka": "^0.5.2",
  • "react": "^16.6.0",
  • "react-dom": "^16.6.0",
  • "react-router-dom": "^5.0.0",

Not using any babel plugin for decorators. Project is React + Typescript (.tsx) based