Not working: require('react/addons')

和自甴很熟 提交于 2019-12-23 20:37:44

问题


I'm using ReactJS & Browserify. I can't figure out why this require doesn't give me access to ReactCSSTransitionGroup:

    var React = require('react/addons');

I tried adding this and it's still not working:

    var ReactCSSTransitionGroup = React.ReactCSSTransitionGroup;

To get it working I had to add:

    var ReactCSSTransitionGroup = require("react/lib/ReactCSSTransitionGroup");

How can I gain access to all addons through: require('react/addons') ?


回答1:


Requiring 'react/addons' simply adds the addons object to React and exports React.

React.addons = {
  CSSTransitionGroup: ReactCSSTransitionGroup,
  LinkedStateMixin: LinkedStateMixin,
  ...

module.exports = React;

As in the docs you can find the animation addon at React.addons.CSSTransitionGroup.

Side note: requiring 'react' and 'react/addons' doesn't include react twice. Some people have asked about that in the past, so I just want to clarify.



来源:https://stackoverflow.com/questions/26965897/not-working-requirereact-addons

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