Answer the question
In order to leave comments, you need to log in
Styling options for a large React app?
There is a react web application, it has a bad styling structure, the usual bam + scss is used, but 5 different components can be mixed in one style file and as a result it is very difficult to edit the styles, there is so much code that you have to use !important, then that you don’t understand where-what-how is stylized.
Later, a react-native web application is planned. What are the styling options? I thought to use styled-component, they would be good for native, but the application is large, it seems to me that it will not be very convenient to use styled-component for the web version. What's the best way to style?
Answer the question
In order to leave comments, you need to log in
Break the styles so that there are styles for one component in one file.
Enable css - modules, remove 99% of the problems.
farther
import styles from './mybutton.module.scss'
...
<div className={styles.title}>
...
<button outlined/>
I like css-in-js the most, if you work with React with hooks, then you can implement css-in-js on hooks. There are many options, but it's better to isolate the styles in the component, you don't have to use variables from scss, it's much easier to use this scheme: the useWindowSize hook (it's easy to google), and then just create a few variables and a handler function:
import useWindowSize from 'yourPathHere/hooks/useWindowSize '
const App = () => {
const size = useWindowSize()
const [width, setWidth] = useState(null)
const [height, setHeight] = useState(null)
const [direction, setDirection] = useState(null)
useEffect(() => {
if (size.width > 1200) {
setWidth('500px')
setHeight('300px')
setDirection('row')
} else if (size.width > 900 && size.width <= 1200) {
setWidth('100%')
setHeight('250px')
setDirection('column')
}
} else return
}, [ size.width ])
// yourCodeHere
}
// Потом в стилях задаете:
text_block: {
width: width
height: height,
display: 'flex',
flexDirection: direction
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question