คำถามติดแท็ก tsx

7
ค่าคุณสมบัติเริ่มต้นในส่วนประกอบ React ใช้ TypeScript
ฉันไม่สามารถหาวิธีตั้งค่าคุณสมบัติเริ่มต้นสำหรับส่วนประกอบของฉันโดยใช้ Typescript นี่คือซอร์สโค้ด: 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> ); } } และเมื่อฉันพยายามใช้องค์ประกอบเช่นนี้ ReactDOM.render(<PageComponent />, document.getElementById("page")); ฉันได้รับข้อผิดพลาดว่าทรัพย์สินfooหายไป ฉันต้องการใช้ค่าเริ่มต้น ฉันยังพยายามใช้static defaultProps = ...ภายในองค์ประกอบ แต่ก็ไม่มีผลตามที่ฉันสงสัย src/typescript/main.tsx(8,17): error TS2324: Property 'foo' …
153 reactjs  typescript  tsx 
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.