【问题标题】:How to use react-swipe as a component?如何使用 react-swipe 作为组件?
【发布时间】:2015-01-19 03:57:59
【问题描述】:

如何在我的 ReactJS 应用程序中使用 react-swipe 作为组件: https://www.npmjs.org/package/react-swipe

我可以从react-swipe NPM 页面获取该示例,但是当尝试类似下面的操作时它不起作用:

注意:如果我使用 {React.DOM.div(null, carousel)} 而不是 <carousel /> 它可以工作。我怎样才能使用 JSX 让它工作?我不知道等效的 JSX。

var App = React.createClass({
   render: function() {
      return (
         <div>

            <carousel />

         </div>
      );
  } 
}); 

React.renderComponent((
   <App />
), document.body);

【问题讨论】:

    标签: reactjs


    【解决方案1】:

    用新鲜的眼光和下面的博客文章,我意识到carousel 不是 React 组件,它只是 JavaScript。我假设 Swipe() 返回了一个 ReactJS 组件。这有效:

    <div>{carousel}</div>
    

    这个博客帮助我解决了这个问题: https://www.packtpub.com/books/content/using-reactjs-without-jsx

    也可以这样做:

     this.carousel = (
          <Swipe continuous={false}>
            <div>
              <MyPrizesPane1 />
            </div>
            <div>
              <MyPrizeOne />
            </div>
          </Swipe>
        );
    

    【讨论】:

      猜你喜欢
      • 2022-01-19
      • 1970-01-01
      • 2019-11-21
      • 1970-01-01
      • 2017-08-18
      • 1970-01-01
      • 2019-08-05
      • 1970-01-01
      • 2021-05-27
      相关资源
      最近更新 更多