Reputation: 2187
we can have dafaultProps
for the interface used in Component class in React. I need to provide a default property in a subtype
which is used in a prop
defined.
There is no separated Component defined for this subtype
export interface TabDetails{
TabTitle? :string|undefined,
Visibility?: boolean,
tabId: string
}
export interface IDynamicTabs{
Tabs : TabDetails[],
onTabVisibilityChanged: (tabId:string, visibility:boolean) => void,
Max : number
}
public class Dynamictabs extends React.Component<IDynamicTabs>
public static defaultProps = {
Max : 5,
// Tabs.Visibility: true // How to define default value?
}
render(){
}
}
In above I can have defaultProps value for Max
but how to define value for TabDetails.Visibility
?
Upvotes: 0
Views: 238
Reputation: 15841
This is done through Props default:
import PropTypes from 'prop-types';
[...]
MyComponent.defaultProps = {
cityList: [],
provinceList: [],
};
MyComponent.propTypes = {
userInfo: PropTypes.object,
cityList: PropTypes.array.isRequired,
provinceList: PropTypes.array.isRequired,
}
Upvotes: 1