属性x在类型react上不存在



我不知道为什么我得到这个错误属性"name"在类型"Portal | undefined"上不存在

下面是我的代码:
export interface Portal {
id: string;
name: string;
announcement?: Announcment;
//highlights: Highlight[];
highlightGroupResults?: HighlightGroup[];
helpfulTips?: HelpfulTip[];
categories: Category[];
helpMessage?: string;
contact: Contact;
}
const [portal, setPortal] = useState<Portal>();
const{
name //where I get the error
} = portal 

使用useState时需要通过初始状态

const [portal, setPortal] = useState<Portal>({id: "",name: "",contact: null});

相关内容

最新更新