Styled Components

This is a sucessor to CSS modules
This allows you to write plain CSS in your components without any class name collisions

npm install --save styled-components 

The CSS is passed in as a template literal.


index.jsx

Import the 'styled' object

import styled from 'styled-components'  

const Button = styled.button`
   font-size : 1.5em;
   background-color : 'red';
`

render (
   <div>
      <Button>My Button</Button>
   </div>
)

Extending an existing styled component

const WhiteButton = Button.extend` 
   color : white;
`

render (
   <div>
      <Button>My Button</Button>
      <WhiteButton>Another Button</WhiteButton>
   </div>
)



© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext