As Developer, We should be aware of all the ways to do a task, So we can perform the job more effeciently. If we talk about styling the componet there are also different ways for the same, including:
Inline styles can be added directly to a component using the style attribute in JSX. Inline styles are defined as an object with CSS property-value pairs.
CSS Modules is a feature of CSS that allows developers to write modular and reusable CSS classes. With CSS Modules, CSS classes are scoped to a particular component, preventing naming conflicts.
There are several CSS-in-JS libraries that allow developers to write CSS styles in JavaScript. These libraries include styled-components, emotion, and glamorous.
Example (using styled-components):
CSS frameworks like Bootstrap or Material UI provide pre-built styles and components that can be used in React applications.
Example (using Material UI):
In this way, We basically follow the general approach of external CSS where we define the styling in an external CSS file and import it wherever needed.
External css file(index.css):
.button {
background-color: 'blue',
color: 'white',
padding: '10px'
}
There are a few more methods to Style the Components but the above listed are the ways that are majorly used.
Let me know your thoughts over email pankaj.itdeveloper@gmail.com. I would love to hear them and If you like this article, share it with your friends.
Thank You