简体   繁体   中英

how to apply PropType in react-native functional component?

I am trying to validate props with PropType but my eslist compiler showing me an error, see image

please correct me whats wrong with this?

在此输入图像描述

What is wrong with the code is that you are using PropTypes instead of propTypes . Notice the lower case 'p'

SubHeader.propTypes = {
    left: PropTypes.array,
    center: PropTypes.array,
    right: PropTypes.array,
 }

There is no difference with stateful components when validating props

Here is the link you want to read more on validating props

As mentioned in the comment, problem us casing of letter. Its lowercase p .

SubHeader.propTypes = {
     left: PropTypes.array,
     center: PropTypes.array,
     right: PropTypes.array,   
 }

Keep this thing in mind always, how we are importing:

import PropTypes from 'prop-types';

and a github issue here and propType docs here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM