How to use this.props in React Styled Components

  javascript, reactjs, styled-components

I am trying to style my component using props likes this:

const MyStyledComponent = styled.div`
    position: fixed;
    top: ${this.props.style.top};
    left: ${this.props.style.left};
    width: ${this.props.style.width};
    height: ${this.props.style.height};
`;

But I am getting the following error:

Uncaught TypeError: Cannot read property ‘props’ of undefined

Source: ReactJs

LEAVE A COMMENT