computed mobx

Estimated reading time: 1 minute

what is computed

computed is a calculation method but return result instance.

// store/Index.js
import {observable, computed} from "mobx";

class OrderLine {
    @observable price = 20;
    @observable vat = 1;

    constructor(price) {
        this.price = price;
    }

    @computed get total() {
        return this.price + this.vat;
    }
}

Access computed

{this.props.store.total}
react, mobx