У меня есть компонент, который получает любую подпорку, которая содержит « data- что угодно». Например, data-test, data-test2 ..
<NotificationComponent id={'ID'} data_test={data}></NotificationsComponent>
Компонент работает правильно, но мне нужно знать, как объявить реквизит в propTypes , что имя будет именем что получено, сначала это будет «неопределено».
Компонент работает правильно, но мне нужно знать, как объявить реквизит в propTypes . Это имя будет именем, полученным реквизитом (« data- как угодно»). Сначала это будет "неопределено".
Я попробовал следующее
class NotificationsComponent extends Component {
render() {
store.addNotification({
title: 'Title',
message: 'Message',
type: 'danger',
container: 'top-right',
animationIn: ["animated", "fadeIn"],
animationOut: ["animated", "fadeOut"],
dismiss:{
showIcon: true,
duration: 8000,
onScreen: true
}
});
return (
<div>
<ReactNotifications />
</div>
);
}
NotificationsComponent.propTypes = {
id: PropTypes.string,
//In the next propType is my problem
//The customProp must change the name by the prop it receive
customProp: function customProp(props, propName, componentName) {
const key = Object.keys(props).find(propKey => {
if (['id'].includes(propKey)
|| (/^data_.+/.test(propKey))) {
return false;
}
return true;
});
if (key) {
return new Error(
'Invalid prop `' + key + '` supplied to' +
' `' + componentName + '`. Validation failed.'
);
}
}
};
export default NotificationsComponent;
, но это не правильно.
Есть идеи?
Спасибо за помощь.