Styled Components => Problem

Hi there.
I am building a simple ternary operator inside the styled component. I got an error message on background-color: ${({ primary }) => (primary ? “red” : “blue”)};

Even the logic works fine, what could be the reason and how to fix it?

Here is the code:

import styled from "styled-components"
import PropTypes from "prop-types";

const StyledButton = styled.button`
  background-color: ${({ primary }) => (primary ? "red" : "blue")};
  display: flex;
  justify-content: center;
  padding: 5px;
  margin: 5px;
  border-radius: 15px;
`;


export default function Button ({primary, text })
 {
    return (
      <div>
        <StyledButton primary={primary}>{text}</StyledButton>
      </div>
    );
}

Button.propTypes = {
    text: PropTypes.string.isRequired,
    primary: PropTypes.bool.isRequired,
  };

Thank you
P.

What error are you getting? The code you posted works for me.

1 Like

The => it’s marked red. Is it normal?

Screenshot 2023-05-29 at 09.01.07

I don’t what is causing that but it looks like a code highlight bug.

It isn’t an error unless you get an error message or the code doesn’t run.

1 Like

Thank you for sharing that. I always associate red color as warning…

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.