加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何加载新版本react addon

发布时间:2020-12-15 04:42:50 所属栏目:百科 来源:网络整理
导读:在低版本的react中,npm调用react addon时,用 var React = require("react/addons"); 但是新版本这样写则报了警告 Warning: require('react/addons') is deprecated. Access using require('react-addons-{addon}') instead 解决需要两个步骤 一:npm下载新

在低版本的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 experimentaland tend to change more often than the core.

  • TransitionGroupandCSSTransitionGroup,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写法 请尽早更改为单独调用形式

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读