如何加载新版本react addon

前端之家收集整理的这篇文章主要介绍了如何加载新版本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 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写法 请尽早更改为单独调用形式

原文链接:https://www.f2er.com/react/307371.html

猜你在找的React相关文章