I am using a variable to conditionally show different JSX and it isn't using the styling that is defined in its parent function. How can I make that work?
You can see a demo here: https://codesandbox.io/s/styled-jsx-example-e6tf6
import React from 'react'
function StyledJsxTest({ isLoggedIn, areButtonsVisible }) {
function renderButtons() {
const buttons = isLoggedIn ? (
<a className="button" href="/dashboard">Dashboard</a>
) : (
<>
<a className="button" href="/signIn">Log In</a>
</>
)
return (
<div>
<div>
<a className="button" href="/dashboard">Test</a>
{buttons}
</div>
<style jsx>{`
.button {
background-color: blue;
color: white;
padding: 20px;
margin: 10px;
}
`}
</style>
</div>
)
}
return (
<div>
<h1>This is a headline</h1>
{renderButtons()}
</div>
)
}
export default StyledJsxTest
The buttons in this chunk of code are not getting the . button
rule. How can i get those to work?
const buttons = isLoggedIn ? (
<a className="button" href="/dashboard">Dashboard</a>
) : (
<>
<a className="button" href="/signIn">Log In</a>
</>
)