Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use mobx Failed to compile err #2367

Closed
zanjs opened this issue May 26, 2017 · 1 comment
Closed

use mobx Failed to compile err #2367

zanjs opened this issue May 26, 2017 · 1 comment

Comments

@zanjs
Copy link

zanjs commented May 26, 2017

Failed to compile
./src/stores/Store.js
Syntax error: E:/2017/react/antd/src/stores/Store.js: Unexpected token (8:2)

   6 | 
   7 | export default class Store {
>  8 |   @observable counter = 10;
     |   ^
   9 | 
  10 |   @observable users = [];
  11 | 

Store.js

import { observable, when, action } from "mobx";
import axios from "axios";
import { fromPromise } from "mobx-utils";

const apiRoot = "https://jsonplaceholder.typicode.com";

export default class Store {
  @observable counter = 10;

  @observable users = [];

  @action increaseCounter() {
    this.counter += 1;
  }
  @action decreaseCounter() {
    this.counter -= 1;
  }
  @action fetch() {
    let fetchResult = fromPromise(axios.get(`${apiRoot}/users`));

    // combine with when..
    when(() => fetchResult.state !== "pending", () => {
      console.log("Got it!");
      this.users = fetchResult.value.data;
    });
  }
}
@zanjs
Copy link
Author

zanjs commented May 26, 2017

https://mobx.js.org/best/decorators.html

@zanjs zanjs closed this as completed May 26, 2017
@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant