MobX http call to Rest API and returning Observable

Viewed 5547

I am trying with MobX. My questions are

  1. Does MobX come with a built http piece? If yes what is the name/function?
  2. If the answer to #1 is no and I use axios how can I convert the resolved promise to my observable?

I know the following is incorrect. What is the common way to achieve this?

export class TodoStore {
  @observable todos = [];
  ....
  fetchTodo() {
    axios.get("http://rest.learncode.academy/api/reacttest/tweets")
      .then((response) => {
        response.data.map(item => {
          this.todos.push(new Todo(item));
      })
      .catch((err) => {
        ....
      });
    });
  }
}
1 Answers
Related