|
|
|
|
|
by giantsloth
3148 days ago
|
|
I agree that single file components are awesome. I wish you had been introduced to styled components in react: import styled from 'styled-components'
const Container = styled.div`
padding: 10px;
background: ${
({ isHovered }) => isHovered ?
'green' :
'red'
};
`
const H1 = styled.h1`
font-size: 15px;
`
const P = styled.p`
font-size: 10px;
`
const MyComponent = ({ isHovered }) => {
return (
<Container
isHovered={isHovered}
>
<H1> Hello <H1>
<P> This is a thing </P>
</Container>
)
}
|
|
> Our designer could churn out neat html/css, but was a beginner in Javascript.
I write JS every day, and frankly that code looks like an unholy mess to me, so I can't imagine what it looks like to a beginner. Is "styled.div``" a function call? It's not self-evident. How do you do inheritance? Is that a template string with functions inside it? Would that CSS autocomplete?
That code looks very much like it sacrifices ease of writing CSS for ease of writing JSX. That isn't the correct tradeoff for everyone.