Ad

Extending Styled Components Properties?

- 1 answer

H1.js

export default styled.h1`
  margin: 0px;
  color: white;
`;

I want to change the color of this component, and I tried

import H1 from "./H1";

const ColoredH1 = styled(H1)`
    color: "black"
`; 

But this is not changing the color of the H1?

Ad

Answer

Don't use "black"with quotes, remember that you write CSS within the styled-component, therefore "black" isn't a valid color, although black do.

const ColoredH1 = styled(H1)`
  /* color: "black"; */  /* Invalid Color */

  color: black;          /* Valid Color */
  color: ${"black"}      /* Or use a valid color representation as String */
`;

Edit Q-58577335-SyledString

Ad
source: stackoverflow.com
Ad