News for hackers. Stuff that matters.
Re:How to start a React Project in 2023 by ggregoire on Thursday March 23, 2023 @07:31PM (#35283025)
Solution 1: You can give a classname to your component and prefix every CSS rule with this classname. e.g. <CustomSelect>, which translates to <div className="custom-select">...</div>, which you can style by prefixing every rule with .custom-select. You put that in a folder CustomSelect with its index.tsx and its index.css and import the CSS file in the TypeScript one.

Solution 2: Otherwise you could try to use CSS modules (Vite supports them out-of-the-box I think).

Solution 3: Otherwise you could try one of the many "CSS-in-JS" libraries like styled-components.

Personally I'm using the solution 1, did for more than a decade, works fine, scales well, nothing to install and learn, just old straightforward CSS.

Re:How to start a React Project in 2023 by bobthepanda on Thursday March 23, 2023 @09:18PM (#35283854)
In practice, I find keeping your CSS separate from the JSX tends to be cleanest (your solution 1).

Separation of concerns with what are essentially totally different markup languages is best when you can. We tolerate it with JSX because there isn't a fantastic first-class declarative way to express an object, a list of objects, or filtering in HTML. (I have seen WebComponents and the MDN tutorial seemed like taking a step back.)