V
V
Vladimir Golub2019-09-16 11:00:52
React
Vladimir Golub, 2019-09-16 11:00:52

Why aren't the styles applied to the component already wrapped (styled-components)?

There is a ListItem component, inside it is nested the Label component, which is already styled earlier.

import Label from './../../Elements/Label/Label';

const LabelStyled = styled(Label)`
    width: 10%;
    flex-grow: 1
`;

export default (props) => {
    return (
        <ListItem>
            <LabelStyled>{ 'Ярлык' }</LabelStyled>
        </ListItem>
    )
}

Label Component
import React from 'react';
import styled from 'styled-components';

const Label = styled.div`
    border: none;
    border-radius: 20px;
    background-color: #f63;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    
`;

export default (props) => {
    return (
        <Label>
            { props.children }
        </Label>
    )
}

As a result, only the styles prescribed for the main styling are applied to the component. There are no errors.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Golub, 2019-09-16
@RazerVG

It turns out you still need to pass className

import React from 'react';
import styled from 'styled-components';

const Label = styled.div`
    border: none;
    border-radius: 20px;
    background-color: #f63;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    
`;

export default (props) => {
    return (
        <Label className={props.className}>
            { props.children }
        </Label>
    )
}

That's how it works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question