就像標題所說的那樣,我遇到了風格化組件的問題。無論我給它們添加什么樣式屬性,它們都不想呈現,它們根本不想呈現。有誰知道我是否打錯了字或類似的東西,如果你能幫助我,我將非常感激。這是我正在使用的代碼。
import React from "reaction"。
import風格化的from "styled-components"。
const testStyled = styled.h1`。
font-size:10px;
`。
export const Datepicker =()=> {
return (
<div>
<testStyled>Test</testStyled>
</div>
);
};
現在我是這樣把它匯入到另一個組件中的:
。import React from "react";
import風格化的from "styled-components"。
import{Datepicker}。from "./Datepicker"。
export const AnotherComponent =()=> {
return (
<div>
<Datepicker></Datepicker>
</div>
);
};
uj5u.com熱心網友回復:
你在這里的問題是,React組件必須以大寫字母開頭,即使它們是風格化的組件。你可以閱讀更多相關內容這里或這里。
你的代碼應該是這樣的
你的代碼應該是這樣的
import React from "reaction";
import風格化的from "styled-components"。
const TestStyled = styled.h1`。
font-size:10px;
`。
export const Datepicker =()=> {
return (
<div>
<TestStyled>Test</TestStyled>
</div>
);
};
uj5u.com熱心網友回復:
React組件使用PascalCase:將testStyled改為TestStyled。
const TestStyled = styled.h1`
font-size:10px;
`。
export const Datepicker =()=> {
return (
<div>
<TestStyled>Test</TestStyled>
</div>
);
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/306986.html
標籤:
