0
我有這個成分嵌套的組件在陣營終極版
type UserInfoProps = UserInfoState.IUserInfoState & typeof UserInfoState.actionCreators
class UserInfo extends React.Component<UserInfoProps, UserInfoState.IUserInfoState>
{
public componentWillMount()
{
this.props.loadUserInfo();
}
public render()
{
return <div>{this.props.firstname + ' ' + this.props.lastname}</div>
}
}
export default connect((state: ApplicationState) => state.userInfo, UserInfoState.actionCreators)(UserInfo) as typeof UserInfo;
和第二部分作爲容器
export default class Dashboard extends React.Component<RouteComponentProps<{}>, {}>
{
public render()
{
return <div><UserInfo /></div>;
}
}
,但我得到這個錯誤
TS2324住宅「姓」中失蹤鍵入'IntrinsicAttributes & IntrinsicClassAttributes &只讀< {ch ildren ?: ReactNode; }> & ...'
我在這裏做錯了什麼,我該怎麼辦?
但我創建'UserInfo'組件來做它的邏輯與干擾的容器。通過這種方式,我必須從類似'loadUserInfo'函數的容器中傳遞所有內容。我在這裏做錯了什麼? – Raika
我在說的是打字稿..你定義了一個組件應該得到的道具。如果你不傳遞這些道具,那麼編譯器將會失敗,並給你那個錯誤信息。要麼你需要將屬性傳遞給組件..或者你需要使這些屬性可選(用'?') –
我知道你在說什麼。但'loadUserInfo'是'actionCreators',不能通過optionnal。 – Raika