Cannot Read Property 'string' Of Undefined | React.proptypes | Layoutproptypes.js
Solution 1:
React.PropTypes is now deprecated:
Note: React.PropTypes is deprecated as of React v15.5. Please use the prop-types library instead.
You need to add the prop-types package separately now. The error most likely just started to show up because you deleted your node_modules
folder and then reinstalled everything which upgraded your react
version.
Solution 2:
React is no more shipped with PropTypes. You will need to install it.
First install the prop-types
package by running npm i prop-types --save
.
Next use the prop-types
package into your component like this:
importReactfrom'react'importPropTypesfrom'prop-types'exportconstAwesomeComponent = props => {
return(
<h1>Hello {props.name}</h1>
)
}
AwesomeComponent.propTypes = {
name: PropTypes.string.isRequired
}
Or simply use an interface if you are using Typescript like this:
import * asReactfrom'react'interface IAwesomeComponentProps {
name: string
}
exportconstAwesomeComponent: React.FC<IAwesomeComponentProps> = props => {
return(
<h1>Hello {props.name}</h1>
)
}
Solution 3:
Are you absolutely sure you are using react 16.0.0-alpha.12
?
Check your package.json if you have a ^
before the react version, if you have, it probably have installed the latest react version, which currently is 16.0.0-alpha.13
, in which it breaks as you say (just had the problem myself). Having the ^
before the version, allows it to install newer minor and patch versions. You can read more about it here.
To keep it at the exact version you specify, simply remove the ^
before the version, so that your package.json looks like this:
"dependencies":{"react":"16.0.0-alpha.12","react-native":"0.45.1",}
Remember to re-install your node_modules after your changes.
Solution 4:
I have the similar problem, no solution. Answers talking about 'prop-types' package are meaningless, the problem is come from react-native source code. That is not an option to manually fix react native source in node_modules folder.
Solution 5:
Now you can update to react-native 0.46.4, just follow along this guide: https://facebook.github.io/react-native/docs/upgrading.html
my package.json looks like this:
"react":"16.0.0-alpha.12","react-native":"0.46.4",
Post a Comment for "Cannot Read Property 'string' Of Undefined | React.proptypes | Layoutproptypes.js"