An Interest In:
Web News this Week
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
What is CSS in JS?
CSS in JS is a way of writing css styles in javascript with much more flexibility and features.
I have already created a video about this on the Cules Coding youtube channel.
Why CSS in JS?
Suppose you have a large-scale application with a lot of components.
Each component has different styles. So you add class names to them. Those
class names have some styling.
Now it is easy to mess up with component names like the picture below.
And your whole layout breaks.
By the way, this blog is originally published on cules coding website.
I would be glad if you give it a visit.
How can this problem be solved?
The solution is Scoping CSS
. Instead of writing css globally in css styles, what if we can write them inside
the component. Then the css styles won't affect other components.
But how do we do something like this?
This is where css-in-js comes into play. Css in js is writing css inside
javascript. And we want to write css inside javascript. Now, what css-in-js
the library will do is, it will generate a unique class name for the component. And
that class will have all the styles.
It will add a unique hash to the class name. Just because the hash will be
unique, that's why all the components will have a different style. Now we have
Scoping CSS.
How do we write CSS in JS?
There are bunch of libraries out there. Popular ones are:
I like the Styled Component most. You can use whatever you want.
Don't think that all you can do with css-in-js is write scoping Css.
There are a lot of features that those libraries provide us. Like theming,
props adaption, extending style, and so on.
And also remember you are writing in JavaScript. That means you can create your
functionalities and features. So, don't let yourself restrict within the library
features.
To learn more watch the video.
Shameless Plug
I have made a video about how to build a carousel postcard with React, Material-UI, and Swiper.js.
If you are interested you can check the video.
You can also demo the application form here
Please like and subscribe to Cules Coding. It motivates me to create more content like this.
If you have any questions, please comment down below.
You can reach out to me on social media as @thatanjan.
Stay safe. Goodbye.
About me
Why do I do what I do?
The Internet has revolutionized our life. I want to make the internet more beautiful and useful.
What do I do?
I ended up being a full-stack software engineer.
What can I do?
I can develop complex full-stack web applications like social media applications or e-commerce sites.
What have I done?
I have developed a social media application called Confession. The goal of this application is to help people overcome their imposter syndrome by sharing our failure stories.
I also love to share my knowledge. So, I run a youtube channel called Cules Coding where I teach people full-stack web development, data structure algorithms, and many more. So, Subscribe to Cules Coding so that you don't miss the cool stuff.
Want to work with me?
I am looking for a team where I can show my ambition and passion and produce great value for them.
Contact me through my email or any social media as @thatanjan. I would be happy to have a touch with you.
Contacts
- Email: [email protected]
- linkedin: @thatanjan
- portfolio: anjan
- Github: @thatanjan
- Instagram (personal): @thatanjan
- Instagram (youtube channel): @thatanjan
- Twitter: @thatanjan
- Facebook: @thatanjan
Blogs you might want to read:
- Eslint, prettier setup with TypeScript and react
- What is Client-Side Rendering?
- What is Server Side Rendering?
- Everything you need to know about tree data structure
- 13 reasons why you should use Nextjs
Videos might you might want to watch:
Original Link: https://dev.to/thatanjan/what-is-css-in-js-c7d
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To