A
A
Andrey Okhotnikov2019-07-24 10:09:58
css
Andrey Okhotnikov, 2019-07-24 10:09:58

Styled components and className?

Is it ok to combine Styled-components and className , for example, use SC for the parent element, and mark all nested elements with className.
It will turn out like this

const List = styled.div`
  list style;

  .list-title {
    
  }

  .list-item {

  }
`

Or is it better
const List = styled.div`
  list style;
`

const ListTitle = styled.div`
  title style;
`

const ListItem = styled.div`
  item style;
`

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2019-07-24
@tsepen

Or is it better

Why you should not do this:
1. Isolation suffers. Any third party library with ccs can break your code in the most unexpected places.
2. Possible problems when changing the structure.
3. Possible problems when adding state properties, on which the layout will depend. You will have to produce state selectors in the old fashioned way or pass properties through the parent.
If you like the second approach more, then you should look towards css modules.

P
Pavel Antonov, 2019-07-24
@freislot

The second option is better, otherwise what's the point of this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question