Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
153
rated 0 times [  158] [ 5]  / answers: 1 / hits: 9945  / 5 Years ago, mon, november 25, 2019, 12:00:00

I have an array of objects



[
{
id: 1,
customtitle: '',
IconSRC: '',
btnColor: '',
inlineSyle: '',
btnStyle: {
width: '100px',
height: '100px',
flexDirection: 'column',

},
num: 1,
},
{
id: 2,
customtitle: '',
IconSRC: '',
btnColor: '',
inlineSyle: '',
btnStyle: {
width: '100px',
height: '100px',
flexDirection: 'column',

},
num: 2,
},]


and i confused to making it work as props validation .I need help to fix it, I try this way



Function.propTypes = {
list: PropTypes.objectOf(PropTypes.shape({
id: PropTypes.number,
btnColor: PropTypes.string,
customTitle: PropTypes.string,
btnStyle:PropTypes.object
IconSRC: PropTypes.string,
inlineSyle: PropTypes.string,
})),
};
Function.defaultProps = {
List: [],
};


But that didn't work.
without this proptypes my component works correctly. but eslint show an error with this text




.map' is missing in props validation eslint(react/prop-types)



More From » reactjs

 Answers
4

What you want is actually PropTypes.arrayOf(). For example:


list: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.number,
btnColor: PropTypes.string,
customTitle: PropTypes.string,
btnStyle:PropTypes.object
IconSRC: PropTypes.string,
inlineSyle: PropTypes.string,
})),

You can see a full list of PropTypes here.


[#5507] Thursday, November 21, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kinsley

Total Points: 352
Total Questions: 84
Total Answers: 94

Location: Denmark
Member since Tue, Jul 19, 2022
2 Years ago
;