[英]React + Typescript context - how to define interface and use it?
[英]How to define an TypeScript interface of an function on a react class?
我要救一個轉診SectionList上this.SectionList
我MessageDialog內。 我嘗試定義接口以允許在第31行使用SectionList,但這無效。 我該怎么辦?
TypeScript抱怨說: MessageDialog.tsx(132,38): error TS2339: Property 'SectionList' does not exist on type 'SkademeldingDialog'
29 interface IComponentProps {
30 navigation: NavigationScreenProp<any, any>;
31 SectionList: any; // I tried to add SectionList here, but that did not work.
32 }
33
34 interface IDispatchToProps {
35 requestHendelsesvelger: RequestHendelsesvelgerInterface;
36 requestProsessguide: RequestProsessguideInterface;
37 }
38
39 type Props = IComponentProps & IDispatchToProps;
121 class MessageDialog extends React.Component<Props> {
128 public render() {
129
130 return (
131 <SectionList
132 ref={(sectionlist) => { this.SectionList = sectionlist; }}
137 >
138 </SectionList>
Props
類型是在組件中鍵入this.props
而不是組件實例本身,您不應該在其中添加SectionList
。 它應該是類的一個屬性,這樣它將在MessageDialog
類型上存在:
class MessageDialog extends React.Component<Props> {
private sectionList: SectionList;
public render() {
return (
<SectionList
ref={(sectionlist) => { this.sectionList = sectionlist; }}
>
</SectionList>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.