I can\'t figure out how to set default property values for my components using Typescript.
This is the source code:
class PageState
{
}
export class
With Typescript 3.0 there is a new solution to this issue:
export interface Props {
name: string;
}
export class Greet extends React.Component {
render() {
const { name } = this.props;
return Hello ${name.toUpperCase()}!;
}
static defaultProps = { name: "world"};
}
// Type-checks! No type assertions needed!
let el =
Note that for this to work you need a newer version of @types/react
than 16.4.6
. It works with 16.4.11
.