Skip to content

Developer Insights

Join millions of viewers! Our engineers craft human-written articles solving real-world problems weekly. Enjoy fresh technical content and numerous interviews featuring modern web advancements with industry leaders and open-source authors.

Newest First
Tags:Emmett Naughton
Using Styled Components with React  cover image

Using Styled Components with React

What are styled-components? Styled Components allow you to style your App through individual React components. Learn more with the offical docs: Offical Docs How to install styled-compoents? You can install styled components like any other Node Package! npm install --save styled-components yarn add styled-components Once you import styled-components into your project, you are free to style your components however you like. The clever thing about styled-components is that you are creating normal reusable components, with your styles attached to them. How to use styled-components? When using styled-components, you dont need to worry about class names, or stylesheets. The styles live in the component files, and can be called and used just like any other JSX. Below, you can see the H1 variable is just a styled h1 tag, using a template literal. Plain CSS is inside the template literal. ` Here is the rendered H1 component. Now that we know how to create a styled component, lets use the power of JavaScript to really customize some components. I am talking about styling buttons using props! Being able to use props in styled components gives you the ability to create multiple buttons without having to create a bunch of CSS classes. There is a primary prop, which sets the color of the button, and the big prop, which changes the size of the button. ` The props can be used on the same button to create unique components without having to create another component in your app. Here is the project: I look forward to seeing what you create using styled-components. 💅...

Let's innovate together!

We're ready to be your trusted technical partners in your digital innovation journey.

Whether it's modernization or custom software solutions, our team of experts can guide you through best practices and how to build scalable, performant software that lasts.

Prefer email? hi@thisdot.co