I'm using React with TypeScript and I've created stateless function. I've removed useless code from the example for readability.
interface CenterBoxProps extends React.Props<CenterBoxProps> {
minHeight?: number;
}
export const CenterBox = (props: CenterBoxProps) => {
const minHeight = props.minHeight || 250;
const style = {
minHeight: minHeight
};
return <div style={style}>Example div</div>;
};
Everything is great and this code is working correctly. But there's my question: how can I define defaultProps
for CenterBox
component?
As it is mentioned in react docs:
(...) They are pure functional transforms of their input, with zero boilerplate. However, you may still specify .propTypes and .defaultProps by setting them as properties on the function, just as you would set them on an ES6 class. (...)
it should be easy as:
CenterBox.defaultProps = {
minHeight: 250
}
But this code generates TSLint error: error TS2339: Property 'defaultProps' does not exist on type '(props: CenterBoxProps) => Element'.
So again: how can I correctly define defaultProps
in my above stack (React + TypeScript)?