如何加载新版本react addon

在低版本的react中,npm调用react addon时,用

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

但是新版本这样写则报了警告

Warning: require('react/addons') is deprecated. Access using require('react-addons-{addon}') instead


解决需要两个步骤

一:npm下载新的addon包,在官网上已经讲的十分清楚


Add-onsEdit on GitHub

The React add-ons are a collection of useful utility modules for building React apps. These should be considered experimental and tend to change more often than the core.

  • TransitionGroup and CSSTransitionGroup, for dealing with animations and transitions that are usually not simple to implement, such as before a component's removal.
  • LinkedStateMixin, to simplify the coordination between user's form input data and the component's state.
  • cloneWithProps, to make shallow copies of React components and change their props.
  • createFragment, to create a set of externally-keyed children.
  • update, a helper function that makes dealing with immutable data in JavaScript easier.
  • PureRenderMixin, a performance booster under certain situations.
  • shallowCompare, a helper function that performs a shallow comparison for props and state in a component to decide if a component should update.

The add-ons below are in the development (unminified) version of React only:

  • TestUtils, simple helpers for writing test cases (unminified build only).
  • Perf, for measuring performance and giving you hint where to optimize.

To get the add-ons, install them individually from npm (e.g., npm install react-addons-pure-render-mixin). We don't support using the addons if you're not using npm.


如我想引入动画插件 则写成

npm install react-addons-css-transition-group


二:引入新的文件

 var React = require("react");
 var CSSTransitionGroup = require('react-addons-css-transition-group')

react的引入是必要的


这样就不会再报警告了 而且react高版本会彻底废弃react/addons写法 请尽早更改为单独调用形式



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值