警告:SceneView有一个名为shouldComponentUpdate()

时间:2017-06-08 17:07:46

标签: react-native react-native-router-flux

大家好:我在react-native项目中使用react-native-router-flux(v.3.39.2),但今天它显示了这个警告:

警告:SceneView有一个名为shouldComponentUpdate()的方法。 扩展React.PureComponent时,不应使用shouldComponentUpdate。如果使用了shouldComponentUpdate,请扩展React.Component。

这是我的切入点:

从'react'导入React; 从'react-native'导入{AppRegistry,StyleSheet,Platform};

从'react-native-router-flux'导入{Scene,Router};

从'./src/components/HomeView'导入HomeView 从'./src/components/ArtistDetailView'

导入ArtistDetailView

export default class platzimusic extends React.Component {   render(){

const isAndroid = Platform.OS === 'android'
return (
  <Router>
    <Scene key="root">
      <Scene key="home" component={HomeView} hideNavBar/>
      <Scene key="artistDetail" component={ArtistDetailView} hideNavBar={isAndroid}/>
    </Scene>
  </Router>
)

} }

AppRegistry.registerComponent('platzimusic',()=&gt; platzimusic);

这是我的package.json:

{
  "name": "platzimusic",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.0.0-alpha.12",
    "react-native": "^0.45.0",
    "react-native-router-flux": "^3.39.2",
    "react-native-vector-icons": "^4.2.0"
  },
  "devDependencies": {
    "babel-jest": "20.0.3",
    "babel-preset-react-native": "1.9.2",
    "jest": "20.0.4",
    "react-test-renderer": "16.0.0-alpha.12"
  },
  "jest": {
    "preset": "react-native"
  }
}

怎么了?

由于

1 个答案:

答案 0 :(得分:0)

问题已解决: https://github.com/aksonov/react-native-experimental-navigation/pull/23(实际更改可在提交时找到,https://github.com/aksonov/react-native-experimental-navigation/pull/23/files

我不确定如何更新package.json文件以正确解决问题,因为我很确定如果您安装npm,更改将会消失,但在此之前,如果您想要删除警告,进入node_modules / react-native-experimental-navigation / NavigationCard.js,然后变换行: class SceneView扩展了React.PureComponent { 至 class SceneView扩展了React.Component {