/ src / DApp.js
DApp.js
 1  /*global web3*/
 2  import React, {Fragment} from 'react';
 3  import EmbarkJS from './embarkArtifacts/embarkjs';
 4  import SimpleStorage from './embarkArtifacts/contracts/SimpleStorage';
 5  
 6  
 7  class App extends React.Component {
 8    constructor(props) {
 9      super(props);
10      this.state = {
11        loading: true,
12        error: ''
13      };
14    }
15  
16    componentDidMount() {
17      EmbarkJS.onReady((err) => {
18        if (err) {
19          this.setState({
20            loading: false,
21            error: 'Error while loading the Dapp: ' + err.message || err
22          });
23        }
24        SimpleStorage.methods.get().call().then((contractVal) => {
25          this.setState({
26            loading: false,
27            contractVal
28          });
29        });
30      });
31    }
32  
33  
34    render() {
35      if (this.state.error) {
36        return <p>{this.state.error}</p>;
37      }
38      if (this.state.loading) {
39        return <p>Loading...</p>;
40      }
41      return (
42        <Fragment>
43          <h3>Value stored in SimpleStorage contract:</h3>
44          {this.state.contractVal}
45        </Fragment>
46      );
47    }
48  }
49  
50  export default App;