Answer the question
In order to leave comments, you need to log in
How to validate a props object with a dynamic key?
In props comes an object of the form:
{
'Динамический_ключ_1': {
id: 1,
title: 'title 1',
text: 'text 1'
},
'Динамический_ключ_2': {
id: 2,
title: 'title 2',
text: 'text 2'
}
}
const id = 25;
if (typeof id !== 'string') throw new Error(`${id} не строка`);
Answer the question
In order to leave comments, you need to log in
There are lines in the documentation about this:
// An object with property values of a certain type
optionalObjectOf: PropTypes.objectOf(PropTypes.number),
// An object taking on a particular shape
optionalObjectWithShape: PropTypes.shape({
color: PropTypes.string,
fontSize: PropTypes.number
}),
PropTypes.objectOf(PropTypes.shape({
id: PropTypes.number,
title: PropTypes.string,
text: PropTypes.string,
}))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question