tsx

Default property value in React component using TypeScript

自作多情 提交于 2019-11-26 11:49:09
问题 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 PageProps { foo: string = \"bar\"; } export class PageComponent extends React.Component<PageProps, PageState> { public render(): JSX.Element { return ( <span>Hello, world</span> ); } } And when I try to use the component like this: ReactDOM.render(<PageComponent />, document.getElementById(\"page\")); I get an error saying property foo is missing