dong3580
V2EX  ›  React

reactjs 组件如何复用?

  •  
  •   dong3580 · Dec 1, 2015 · 2262 views
    This topic created in 3821 days ago, the information mentioned may be changed or developed.

    并未看懂这篇文档 里面的重用组件。
    掳了掳代码,想在 example1 和 example2 上分别附上该组件

    http://jsbin.com/vivufo/edit?html,js,output

    不知如何在 另一个 div  上复用?

    1 replies    2015-12-02 14:56:18 +08:00
    dong3580
        1
    dong3580  
    OP
       Dec 2, 2015
    已经解决。
    看到有人收藏,给以后的童鞋回复一下:

    React.render 复用组件最外层只能有一级节点,所以如果需要输入多个<TweetBox/>控件,则需要

    React.render(
    <div><TweetBox /><TweetBox/></div>, document.getElementById("example1")
    );

    用 div 或其它 包装成一级节点 就行了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4807 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 09:53 · PVG 17:53 · LAX 02:53 · JFK 05:53
    ♥ Do have faith in what you're doing.