简体   繁体   English

在反应中,我创建了包装器组件。所以现在我需要在我的 app.tsx 中的元素参数中使用它们,该参数位于路由标记中。但是错误不是 jsx elem

[英]In react I had created wrapper components.So now i need to use them in my app.tsx in element parameter which is in route tag.But error as not jsx elem

'Catalog' cannot be used as a JSX component. “目录”不能用作 JSX 组件。 Its return type 'CatalogState' is not a valid JSX element.它的返回类型“CatalogState”不是有效的 JSX 元素。 Type 'CatalogState' is missing the following properties from type 'ReactElement<any, any>': type, props, keyts(2786) “CatalogState”类型缺少“ReactElement<any,any>”类型的以下属性:类型、道具、keyts(2786)

here catalog is my wrapper component THIS IS THE ROUTE PART WHERE I AM USING CATALOG AS A WRAPPER COMPONENT这里目录是我的包装器组件这是我使用目录作为包装器组件的路线部分

<Routes>
       {/* <Route path={BASE}/></Catalog> */}
        {/* <Route path={BASE} element={<PrimeCatalogContainer/>} /> */}
        <Route path={BASE} element={()=>(<Catalog><PrimeCatalogContainer/></Catalog>)}/>
        <Route path={PRIME_CATALOG} element={<PrimeCatalogContainer />} />
        <Route path={PRIME_TRAINING} element={<PrimeTrainingPage />} />
        <Route path={PRIME_INSTANCE} element={<PrimeInstancePage />} />
        <Route path={PRIME_ALMPROFILE} element={<ALMProfilePage />} />
        <Route 
          path={PRIME_BOARDPAGE}
          element={<PrimeCommunityBoardPage />}
        />
        <Route
          path={PRIME_BOARDLIST}
          element={<PrimeCommunityBoardList />}
        />
    </Routes>

CATALOG COMPONENT目录组件

import { PrimeCatalogContainer } from "./almLib";
const Catalog = () =>{
  return(
    <>
    <div
        className="catalog_container"
        data-show-filters="true"
        data-show-search="true"
        data-catalogs="true"
        data-lo-types="true"
        data-skill-name="true"
        data-lo-format="true"
        data-duration="true"
        data-price="true"
        data-skills-level="true"
        data-learner-state="true"
        data-tag-name="true"
        data-skill-level="true"><PrimeCatalogContainer/>
     </div>
    </>
  );
};

instead of above catalogcomponent I tried below one also而不是上面的目录组件,我也尝试了下面的一个

import { PrimeCatalogContainer } from "./almLib";
  function Catalog (): JSX.Element {
    return(
        <div
        className="catalog__container"
        data-show-filters="true"
        data-show-search="true"
        data-catalogs="true"
        data-lo-types="true"
        data-skill-name="true"
        data-lo-format="true"
        data-duration="true"
        data-price="true"
        data-skills-level="true"
        data-learner-state="true"
        data-tag-name="true"
        data-skill-level="true"
      ><PrimeCatalogContainer/></div>
    );
 };

As stated in the docs , element should be a ReactNode, so instead of:文档中所述, element应该是一个 ReactNode,而不是:

<Route path={BASE} element={()=>(<Catalog><PrimeCatalogContainer/></Catalog>)}/>

you need to return the actual Catalog您需要返回实际的目录

<Route path={BASE} element={<Catalog><PrimeCatalogContainer/></Catalog>}/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 React 中使用 App.tsx 而不是 App.js? - How do I use App.tsx instead of App.js in React? &#39;Router&#39; 不能用作 JSX 组件。 在我在 index.tsx 中添加组件 Msal 组件和在 app.tsx 中添加 PageLayout 之前,它工作正常 - 'Router' cannot be used as a JSX component. It was working fine until I added the component Msal componant in index.tsx and PageLayout in app.tsx 如何在 _app.tsx (NextJS) 中使用 Redux state - How to use Redux state in _app.tsx (NextJS) 无法在 app.tsx 中导入 tsx 组件 - Unable to import tsx component in app.tsx 当我需要在元素之间动态添加标记时,如何解决React JSX的相邻组件包装器错误? - How do I resolve React JSX's adjacent component wrapper error when I need to dynamically add markup in between elements? 如何将JSX导入.tsx文件(不在React中)? - How do I import JSX into .tsx file (not in React)? 我可以在 React 的 JSX / TSX 中直接调用 HOC 吗? - Can I call HOC directly from within JSX / TSX in React? 将 TSX/JSX React 转换为字符串或 DOM 元素 - Turning a TSX/JSX React into a string or DOM element 我在反应中收到此错误:JSX 元素“h1”没有相应的结束标记 - I am getting this error in react : JSX element 'h1' has no corresponding closing tag 如何使用 _app.tsx 配置 redux? - How to configure redux with _app.tsx?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM