Reputation: 17467
I have the following prop
this.props.history.push('/');
Which throws an error when trying to validate
AddPerson.propTypes = {
history: React.PropTypes.Object,
}
My declarations
import React, { Component } from 'react';
import axios from 'axios';
Any idea how I can validate this property?
Edit:
So my declaration now look like
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import axios from 'axios';
and because history is a not required prop I used default props.
AddPerson.defaultProps = {
history: PropTypes.Object,
};
Hope this helps someone.
Upvotes: 0
Views: 1405
Reputation: 290
Might you could do the prop type like:
PropTypes.oneOfType([PropTypes.object])
Upvotes: 0
Reputation: 32327
It should be
AddPerson.propTypes = {
history: React.PropTypes.object
}
instead of
AddPerson.propTypes = {
history: React.PropTypes.Object //should be object
}
Upvotes: 2
Reputation: 17467
So my declaration now look like
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import axios from 'axios';
and because history is a not required prop I used default props.
AddPerson.defaultProps = {
history: PropTypes.Object,
};
Upvotes: 0