首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用React中的毛毛雨库时出现问题

使用React中的毛毛雨库时出现问题
EN

Ethereum用户
提问于 2018-09-05 15:22:05
回答 1查看 805关注 0票数 5

使用Ubuntu 16.04

问候,我所遵循的教程,让毛毛雨和运行定位这里。当我试图使用终端上的"npm“命令运行应用程序时,我进入了步骤。然后我遇到了一个错误,上面写着"TypeError:毛毛雨是未定义的“。在通过npm更新软件包之后,我再次尝试,但错误继续存在。我已经复制了下面使用的代码:

app.js:

代码语言:javascript
复制
    import React, { Component } from 'react';
    import logo from './logo.svg';
    import './App.css';

    class App extends Component {
      state = { loading: true, drizzleState: null };

      componentDidMount() {
        const { drizzle } = this.props;

        // subscribe to changes in the store
        this.unsubscribe = drizzle.store.subscribe(() => {

          // every time the store updates, grab the state from drizzle
          const drizzleState = drizzle.store.getState();

          // check to see if it's ready, if so, update local component state
          if (drizzleState.drizzleStatus.initialized) {
            this.setState({ loading: false, drizzleState });
          }
        });
      }

      compomentWillUnmount() {
        this.unsubscribe();
      }

      render() {
        if (this.state.loading) return "Loading Drizzle...";
        return <div className="App">Drizzle is ready</div>;
      }
    }

    export default App;

index.js

代码语言:javascript
复制
            import React from 'react';
            import ReactDOM from 'react-dom';
            import './index.css';
            import App from './App';
            import registerServiceWorker from './registerServiceWorker';
            // import drizzle functions and contract artifact
            import { Drizzle, generateStore } from "drizzle";
            import 'contract_name' from "./contracts/'contract_name'.json";

            ReactDOM.render(<App />, document.getElementById('root'));
            registerServiceWorker();

            // let drizzle know what contracts we want
            const options = { contracts: ['contract_name'] };

            // setup the drizzle store and drizzle
            const drizzleStore = generateStore(this.props.options);
            const drizzle = new Drizzle(this.props.options, drizzleStore);

出于隐私原因,我用“contract_name”替换了合同的实际名称。有什么明显的事情我做错了吗?

EN

回答 1

Ethereum用户

回答已采纳

发布于 2018-09-14 17:18:14

在您的index.js文件中,您需要将毛毛雨实例作为支持传递到:

代码语言:javascript
复制
ReactDOM.render(<App drizzle={drizzle} />, document.getElementById("root"));

您还应该在ReactDOM.render之前声明您的consts:

代码语言:javascript
复制
...
// let drizzle know what contracts we want
const options = { contracts: [MyStringStore] };

// setup the drizzle store and drizzle
const drizzleStore = generateStore(options);
const drizzle = new Drizzle(options, drizzleStore);

// pass in the drizzle instance
ReactDOM.render(<App drizzle={drizzle} />, document.getElementById("root"));
registerServiceWorker();
票数 5
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/58136

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档