javascript - React & Meteor componentDidMount 说明

标签 javascript meteor reactjs

按照 meteor react 待办事项教程,

我对以下代码行感到困惑,有人可以解释一下这里发生了什么,因为我觉得在使用其他包时需要经常使用它。

// we create the account ui component
AccountsUIWrapper = React.createClass({
  componentDidMount() {
    // use meteor blaze to render the login buttons
    this.view = Blaze.render(Template.loginButtons,
    React.findDOMNode(this.refs.container));
  },
  componentWillUnmount() {
    // clean up blaze view
    Blaze.remove(this.view);
  },
  render() {
    return <span ref="container" />;
  }
}); 

谢谢!

最佳答案

根据您最近的评论,似乎困惑在于仅包含 <span ref=container /> 的渲染函数。我不熟悉 Meteor/Blaze,但我可以根据 react 给出足够有根据的答案。本质上发生的事情是在初始渲染之后,调用 componentDidMount 。你有:

Blaze.render(Template.loginButtons,
React.findDOMNode(this.refs.container))

这是在 <span ref=container> 上附加/呈现登录按钮(React.findDOMNode(this.refs.container) 将返回 this.refs 引用的节点)。

关于javascript - React & Meteor componentDidMount 说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35025889/

相关文章:

javascript - React-Redux:如何添加数组中的每个项目

reactjs - Axios 请求超时

javascript - 允许用户获取部分网页的 'screenshot'

meteor - 我如何在 Coffeescript 中编写 Meteor 包?

javascript - 是否可以在 Node 7 中使用 --harmony_async_await 跨异步/等待边界获取堆栈跟踪?

meteor - 我如何使用 collection.find 作为 meteor 方法的结果?

javascript - Angular2 View 在回调函数后未更新

javascript - 带有 React 的 Google map - "Required props loadingElement or googleMapURL is missing. You need to provide both of them"

javascript - 如何在 React 中将变量从一个方法传递到另一个方法

javascript - 使用 keystone-storage-adapter-s3 后出现字段错误