reactjs 在< text>此浏览器中无法识别标记,如果要呈现React组件,请以大写字母开头

tnkciper  于 2023-03-12  发布在  React
关注(0)|答案(1)|浏览(211)

问题

我刚刚尝试通过vite上的样式化组件构建一个组件。但是,当我尝试使用样式化组件中的文本时,它在控制台上抛出了一个错误:

Warning: The tag <text> is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase letter.
    at text
    at O2 (http://localhost:5173/node_modules/.vite/deps/styled-components.js?v=b320d886:1423:6)
    at TextView (http://localhost:5173/src/components/TextView/index.jsx?t=1678354528314:18:3)
    at Header
    at App
printWarning                @   react-dom.development.js:86
error                       @   react-dom.development.js:60
createElement               @   react-dom.development.js:9816
createInstance              @   react-dom.development.js:10941
completeWork                @   react-dom.development.js:22187
completeUnitOfWork          @   react-dom.development.js:26596
performUnitOfWork           @   react-dom.development.js:26568
workLoopSync                @   react-dom.development.js:26466
renderRootSync              @   react-dom.development.js:26434
performConcurrentWorkOnRoot @   react-dom.development.js:25738
workLoop                    @   scheduler.development.js:266
flushWork                   @   scheduler.development.js:239
performWorkUntilDeadline    @   scheduler.development.js:533

编号

import styled from 'styled-components';
// import variablesBreakpoints from '../../helpers/variablesBreakpoints';

function TextView({ children, color, fontSize, fontWeight }) {
  const StyledText = styled.text`
    color: ${color};
    font-size: ${fontSize};
    font-weight: ${fontWeight};
  `;

  return <StyledText>{children}</StyledText>;
}

TextView.defaultProps = {
  color: '#fff',
  fontSize: '1em',
  fontWeight: 'normal',
};

export default TextView;

注解

1.我没有转换为大写,因为它会自动转换。
1.我做了一个研究,我看到了插件。

nbnkbykc

nbnkbykc1#

styled.text存在时,它应该只在SVG context中使用。
如果您想在其他地方使用它,如问题注解中的Undo所建议的,请使用<p><span>标记(因此分别为styled.pstyled.span)。

相关问题