In foo.js
I have:
import Bar from "./bar.js"
function Foo() {
const [myProp, setMyProp] = useState("red");
return(
<div>
<Bar prop={myProp}/>
</div>
)
}
In bar.js
I have:
import styled from "styled-components"
const MyStyledComponent = styled.h1`
font-size: 2rem;
color: props.color;
`
function Bar() {
return(
<MyStyledComponent/>
)
}
Of course, color: props.color
doesn't work outside of the function Bar
. How do I access Bar
's myProp
property without putting MyStyledComponent
inside the function and sacrificing good practices?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…