简体   繁体   English

警告:<link> 使用了不正确的大小写。 将 PascalCase 用于 React 组件

[英]Warning: <Link /> is using incorrect casing. Use PascalCase for React components

I'm trying to use React.createElement to render a Link.我正在尝试使用 React.createElement 来呈现链接。

My code:我的代码:

    createElement(
    item.to ? "Link" : "div",
    {
        className: slidebar ? "slidebar-row" : "header-menu-element",
        onClick: showSubMenu,
        to: item.to
    },
    [
        <button>{item.title}</button>,
        slidebar ? subMenu ?
            item.iconSlidebarOpened :
            item.iconSlidebarClosed :
            subMenu ? item.iconHeaderMenuOpened : item.iconHeaderMenuClosed
    ]
)

The error:错误:

 > Warning: <Link /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.

You should pass the actual Link component from react-router-dom when wanting to create from other React components.当想要从其他 React 组件创建时,您应该从react-router-dom传递实际Link组件。

Create and return a new React element of the given type.创建并返回给定类型的新 React 元素。 The type argument can be either a tag name string (such as 'div' or 'span' ), a React component type (a class or a function) , or a React fragment type. type 参数可以是标签名称字符串(例如'div''span' )、 React 组件类型(class 或函数)或 React 片段类型。

import { Link } from 'react-router-dom';

createElement(
  item.to ? Link : "div", // <-- Link, not "Link"
  {
    className: slidebar ? "slidebar-row" : "header-menu-element",
    onClick: showSubMenu,
    to: item.to
  },
  [
    <button>{item.title}</button>,
    slidebar ? subMenu ?
      item.iconSlidebarOpened :
      item.iconSlidebarClosed :
      subMenu ? item.iconHeaderMenuOpened : item.iconHeaderMenuClosed
  ]
)

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

相关问题 警告:<elementType /> 使用不正确的大小写。 对 React 组件使用 PascalCase,对 HTML 元素使用小写 - Warning: <elementType /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements 警告:<element /> 使用不正确的大小写。 对 React 组件使用 PascalCase,或对 HTML 元素使用小写 - Warning: <Element /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements es-lint 发出警告,提示```存在多个名称仅大小写不同的模块。``` 用于 node_modules - es-lint is throwing a warning for ```There are multiple modules with names that only differ in casing.``` for node_modules React 中动态呈现的组件不正确的大小写错误 - Incorrect casing error with dynamically rendered component in React 动态标签不正确的大小写 - Dynamic tag incorrect casing 在 index.html 中使用来自 CDN 链接的 React 组件 - Use React components from a cdn link, in an index.html 反应复合组件类型警告 - React Compound Components type warning 动态导入的 React 组件的样式组件警告 - Styled Components warning for dynamically imported React components 我可以使用 npm 链接来附加 React 组件吗? - Can i use npm link to attach React components? 如何使用 React Router 正确链接组件? - How do I Link Components correctly using React Router?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM