我想通过useEffect()(并将它们设置为状态)获取应用程序根组件中的数据,然后将状态传递给我的自定义组件。我可以使用 JS 完成此操作,但相同的步骤不适用于 Typescript。
我的错误消息如下:
Type '{ obj: Person; }' is not assignable to type 'IntrinsicAttributes
& Person & { children?: ReactNode; }'. Property 'obj' does not exist
on type 'IntrinsicAttributes & Person & { children?: ReactNode; }'.TS2322
Run Code Online (Sandbox Code Playgroud)
对我来说,看起来我有一个 Person 类型的对象,我无法分配给另一种类型的 Person...
import React, { useState, useEffect } from 'react';
import Profile from '../Profile';
export interface Person {
name: string;
email: string;
dob: string;
address: string;
number: string;
userName: string;
pssw: string;
};
const initPerson: Person …Run Code Online (Sandbox Code Playgroud)