英文:
The tag <text> is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase letter
问题
警告:此浏览器不识别<text>标记。如果您想要渲染一个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 <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
Code
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;
Note
- I didn't convert with uppercase because it does automatically.
- I done a research and I saw plugins about that.
答案1
得分: 1
styled.text
存在,但它应该仅在SVG上下文中使用。
如果您想在其他地方使用它,正如Undo在问题评论中建议的那样,可以使用<p>
或<span>
标签(分别使用styled.p
或styled.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 <p>
or <span>
tags instead (so respectively styled.p
or styled.span
).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论