[英]"Type '{ children: Element[]; pictureUrl: string; }' is not assignable to type 'IntrinsicAttributes & { children?: ReactNode; }'
[英]Type '{ label: string; }' is not assignable to type 'IntrinsicAttributes & { children?: ReactNode; }'
我正在使用 Fluent UI,導入了 Toggle 組件並導出了 UI Toggle:
export const UIToggle: React.FunctionComponent = () => {
return (
<Stack tokens={stackTokens}>
<Toggle label="Enabled and checked" defaultChecked onText="On" offText="Off" />
</Stack>
);
};
但是當我想使用它並更新“標簽”屬性時:
<UIToggle label = "Turn on"></UIToggle>
這是錯誤:
Type '{ label: string; }' is not assignable to type 'IntrinsicAttributes & { children?: ReactNode; }'.
Property 'label' does not exist on type 'IntrinsicAttributes & { children?: ReactNode; }'
誰能解釋為什么會出現此錯誤以及如何解決?
我需要提供 label 作為接口的參數。 通過以下修訂,它現在運行良好
import * as React from 'react';
import { Stack, IStackTokens } from '@fluentui/react/lib/Stack';
import { Toggle } from '@fluentui/react/lib/Toggle';
const stackTokens: IStackTokens = { childrenGap: 10 };
interface ILabels {
label: string
}
export const UIToggle: React.FunctionComponent<ILabels> = (props) => {
return (
<Stack tokens={stackTokens}>
<Toggle label={props.label} defaultChecked onText="On" offText="Off" />
</Stack>
);
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.