首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类型'{子:元素;}‘不能分配到键入'IntrinsicAttributes & ReactNode’

类型'{子:元素;}‘不能分配到键入'IntrinsicAttributes & ReactNode’
EN

Stack Overflow用户
提问于 2022-08-19 13:03:00
回答 1查看 892关注 0票数 -1

这里有这个错误:

类型'{子元素;}‘不能分配给键入'IntrinsicAttributes & ReactNode’。

代码语言:javascript
复制
export const withAppProvider = (Component: AppComponent) => {
  return function WrapperComponent(props: any) {
    return (
      <AppProvider> // <-- here
        <Component {...props} />
      </AppProvider>
    );
  };
};

也许AppProvider声明有什么问题吗?

代码语言:javascript
复制
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) => {做的

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-19 13:38:33

如果它被定义为children支柱,那么问题就消失了。

代码语言:javascript
复制
interface IProps {
  children: React.ReactNode;
}
export const AppProvider = ({children}: IProps ) => {}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73417226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档