The tag <text> is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase letter

huangapple go评论135阅读模式
英文:

The tag <text> is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase letter

问题

警告:此浏览器不识别&lt;text&gt;标记。如果您想要渲染一个React组件,请以大写字母开头命名它。
    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. 我没有转换为大写因为它会自动完成
 2. 我做了一些研究发现了一些相关的插件
英文:

Problem

I just tried to build a component via styled components on vite. But, When I try to use text from styled components, It throws an error on console:

Warning: The tag &lt;text&gt; 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

Code

import styled from &#39;styled-components&#39;;
// import variablesBreakpoints from &#39;../../helpers/variablesBreakpoints&#39;;

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

  return &lt;StyledText&gt;{children}&lt;/StyledText&gt;;
}

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

export default TextView;

Note

  1. I didn't convert with uppercase because it does automatically.
  2. I done a research and I saw plugins about that.

答案1

得分: 1

styled.text 存在,但它应该仅在SVG上下文中使用。

如果您想在其他地方使用它,正如Undo在问题评论中建议的那样,可以使用&lt;p&gt;&lt;span&gt;标签(分别使用styled.pstyled.span)。

英文:

While styled.text exists, it is supposed to be used only in SVG context.

If you want to use it somewhere else, as suggested by Undo in the question comment, use &lt;p&gt; or &lt;span&gt; tags instead (so respectively styled.p or styled.span).

huangapple
  • 本文由 发表于 2023年3月9日 17:49:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75682879.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定