Bootstrap with React: accordion won't work

守給你的承諾、 提交于 2019-12-24 02:33:37

问题


I am trying to get a bootstrap accordion running, where my panels are React classes. Somehow this doesn't work:

<ReactBootstrap.Accordion>
   <WontWorkPanel pkey={1} />
   <WontWorkPanel pkey={2} />
</ReactBootstrap.Accordion>

http://jsfiddle.net/3azxcquh/

The WontWorkPanel is React class that renders the single panel with the key this.props.pkey .

Could someone explain me what I'm doing wrong, or how to do it better?

Thanks!


回答1:


The Accordion clones its children with new props, and those props control the showing/hiding of the Panel component. To allow that to still work with a custom Panel wrapper, you need to transfer props from the wrapper to the Panel child:

Fiddle: http://jsfiddle.net/ssorallen/3azxcquh/6/

var WontWorkPanel = React.createClass({
  render: function() {
    return this.transferPropsTo( 
      <ReactBootstrap.Panel header={"WontWork " + this.props.key} key={this.props.key}>
        Anim pariatur cliche reprehenderit, enim eiusmod high life
        accusamus terry richardson ad squid. 3 wolf moon officia aute,
        non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt
        laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua pu
      </ReactBootstrap.Panel>
    );
  }
});


来源:https://stackoverflow.com/questions/25886660/bootstrap-with-react-accordion-wont-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!