Plee
May 28, 2023, 11:53am
1
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
Plee
May 29, 2023, 7:01am
3
The => it’s marked red. Is it normal?
I don’t what is causing that but it looks like a code highlight bug.
opened 08:06PM - 05 Aug 22 UTC
closed 12:46PM - 07 Dec 22 UTC
info-needed
Type: <b>Bug</b>
In Typescript, using the Default Dark+ theme, the right care… t is being colored red in comparisons (greater than, greater than or equals), and in fat arrows (=>).


VS Code version: Code 1.70.0 (da76f93349a72022ca4670c1b84860304616aaa2, 2022-08-04T04:38:55.829Z)
OS version: Darwin x64 18.7.0
Modes:
Remote OS version: Linux x64 5.4.0-107-generic
Remote OS version: Linux x64 4.15.0-70-generic
<details>
<summary>System Info</summary>
|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i7-3820QM CPU @ 2.70GHz (8 x 2700)|
|GPU Status|2d_canvas: enabled<br>canvas_oop_rasterization: disabled_off<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>metal: disabled_off<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>skia_renderer: enabled_on<br>video_decode: enabled<br>video_encode: enabled<br>webgl: enabled<br>webgl2: enabled|
|Load (avg)|2, 2, 2|
|Memory (System)|16.00GB (3.23GB free)|
|Process Argv|--crash-reporter-id b304ab23-9781-4187-967b-efb5b43bd9d1|
|Screen Reader|no|
|VM|0%|
|Item|Value|
|---|---|
|Remote|SSH: dev-app6|
|OS|Linux x64 5.4.0-107-generic|
|CPUs|Intel Xeon Processor (Skylake, IBRS) (16 x 2399)|
|Memory (System)|15.63GB (6.96GB free)|
|VM|0%|
|Item|Value|
|---|---|
|Remote|SSH: mfcalerts1|
|OS|Linux x64 4.15.0-70-generic|
|CPUs|Intel(R) Xeon(R) Gold 6130 CPU @ 2.10GHz (32 x 1028)|
|Memory (System)|62.58GB (0.57GB free)|
|VM|0%|
</details><details><summary>Extensions (17)</summary>
Extension|Author (truncated)|Version
---|---|---
language-prometheus|caa|0.1.2
vscode-nginx-conf-hint|han|0.3.0
jupyter-keymap|ms-|1.0.0
remote-ssh|ms-|0.84.0
remote-ssh-edit|ms-|0.80.0
npm-intellisense|chr|1.4.2
vscode-eslint|dba|2.2.6
gitlens|eam|12.1.2
copilot|Git|1.38.6394
Untabify|ili|0.0.2
python|ms-|2022.12.0
vscode-pylance|ms-|2022.8.10
typescript-javascript-grammar|ms-|0.0.55
indent-space|SCG|0.4.0
language-stylus|sys|1.16.0
shellcheck|tim|0.19.6
vscodeintellicode|Vis|1.2.22
(3 theme extensions excluded)
</details>
It isn’t an error unless you get an error message or the code doesn’t run.
1 Like
Plee
May 30, 2023, 7:45am
5
Thank you for sharing that. I always associate red color as warning…
system
Closed
November 28, 2023, 7:45pm
6
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.