Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactNative.createClass is deprecated use React.createClass from "React" package instead

Anyone knows why this warning is heading up ?

another warning is : ReactNative.createElement is deprecated. Use React.createElement from "react" package instead.

Code is :

var React = require('react-native');

var {
Text,
View,
StyleSheet,
} = React;

module.exports = React.createClass({
render: function(){
return(
  <View>
    <Text>{this.props.titleName}</Text>
  </View>
);
}
});

var styles = StyleSheet.create({
container:{

},
text:{

}
});
like image 748
Rajesh Avatar asked May 05 '16 14:05

Rajesh


1 Answers

Importing React from react-native has been deprecated in 0.25.1. It will stop working in 0.26.

You should do this now:

import React from 'react';

import {
    Text,
    View,
    StyleSheet,
} from 'react-native';

Edit: If you still get deprecation warnings after fixing your code, you are probably using dependencies that have not yet been updated. To fix these warnings do the following:

  1. Check if there are updates available that fix the imports.
  2. Use this script to rewrite your dependencies to use the correct imports automatically. It will take quite some time and rewrite some files that have nothing to do with react. jscodeshift -t transform.js PATH_TO_YOUR_PROJECT/node_modules/
  3. To find the remaining files that require React from react-native you can set a breakpoint in node_modules/react-native/Libraries/ReactNative/ReactNative.js at line 41 that is where the warning is triggered.

When you find a dependency that has not been updated it's probably a good idea to submit an issue or if you have the time a PR.

like image 157
Daniel Basedow Avatar answered Oct 06 '22 17:10

Daniel Basedow