[英]"Type '{ children: Element[]; pictureUrl: string; }' is not assignable to type 'IntrinsicAttributes & { children?: ReactNode; }'
[英]Type '{ children: Element; }' is not assignable to type 'IntrinsicAttributes & ReactNode'
在這里得到這個錯誤:
類型'{孩子:元素; }' 不可分配給類型 'IntrinsicAttributes & ReactNode'。
export const withAppProvider = (Component: AppComponent) => {
return function WrapperComponent(props: any) {
return (
<AppProvider> // <-- here
<Component {...props} />
</AppProvider>
);
};
};
AppProvider
聲明可能有問題?
export const AppProvider = (children: ReactNode) => {
const { width, height } = useWindowSize();
const isClient = useClient();
const isMobile = isClient ? width < 1200 : false;
return (
<AppContext.Provider
value={{
isClient,
isMobile,
}}
>
{children}
</AppContext.Provider>
);
};
通過export const AppProvider = (children: React.ReactNode) => {
Type error: Type '{ children: Element; }' is not assignable to type 'IntrinsicAttributes & ReactNode'.
Type '{ children: Element; }' is missing the following properties from type 'ReactPortal': key, type, props
如果它被定義為children
道具,問題就消失了。
interface IProps {
children: React.ReactNode;
}
export const AppProvider = ({children}: IProps ) => {}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.