Is there a way around not using inline CSS in React when you have something as follows:
const stylesObj = { width: 10, height: 20 };
<div className="point-class"
style={{
width: stylesObj.width + "px",
height: stylesObj.height + "px",
}}
></div>
2
Answers
you can always change your global.css file
or use this method to add css modules https://create-react-app.dev/docs/adding-a-css-modules-stylesheet/
You can use a more stable approach by defining the style object outside of the component render function.
By defining the styles object outside the component, it remains the same between renders, ensuring that the style prop won’t trigger unnecessary re-renders.