Hire a web Developer and Designer to upgrade and boost your online presence with cutting edge Technologies

Thursday, July 13, 2023

React native Undefined is not an object issues

 In react native recently many people facing the undefined object issue related to "PropTypes.bool " and "createClass" . This kind of issue ruining the more development time now a days.  Today we are going to look at the exact problem and the solution for this kind of errors


Problem Description:

As of now we are going to see the React native Undefined is not an object (evaluating'_react2.default.PropTypes.bool')  . In this issue we cant do the property check for the element using the react native.

Screen shot :


Root Cause: 

  1. The problem arise because of outdated package using in the application. Which  means the react version being in higher/upgraded and the other packages not updated and used old only. 
  2. May be the react and react native latest version they deprecated the functionalities which you using in application
Solution:

The above problem is arrived because of second root cause point. So we have to make sure the up gradation done safely.  
They removed the PropTypes from the react in the version of above 16.  The older one will support the React.PropTypes.bool but the newer version have the separate package for PropTypes which name is prop-types
The package install command is given below through the npm


1
sudo npm install prop-types --save

After install the package need to import into application. The sample import and usage of the PropsType example,


1
2
3
import PropTypes from 'prop-types';
//Usage like given below
PropTypes.bool


React.createClass Issue:

Due to updates on the latest versions of React, in order to use Create Class you'll need to import an additional package


1
sudo npm install create-react-class --save

And then change the way you do the Create Class like this


1
2
var createReactClass = require('create-react-class');
const Scoreboard = createReactClass({ ...

Note :  Once going to update the react and react native version, you have to make sure the all other dependencies have any changes and the package support have or not. This kind of issue only now a days ruining the development time much more

No comments:

Post a Comment