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

How to get the mobx observer value in react component ?

Aniketh Saha's photo
Aniketh Saha
·Aug 27, 2019

how to get the observer value in the react component> I have a store with simple object observer

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

class TaskStore {
    @observable public task = {};
    @observable public boards = [];

    @action public addNewTaskJson(storageJson: Object[]) {
        this.task = storageJson;
    }
    public get getTask() {
        return this.task;
    }
}

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

AND THE COMPONENT I am having simple like this

@inject("TaskStore")
@observer
export default class TaskContainer extends React.Component<ITaskContainerProps, ITaskContainerState> {
    constructor(props: ITaskContainerProps) {
        super(props);
    }
    public componentDidMount() {
        console.log("TaskStore.task", this.props.TaskStore.task);
    }
....
....
...

And In this log, I am getting like this