Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
73
rated 0 times [  76] [ 3]  / answers: 1 / hits: 8160  / 4 Years ago, wed, september 9, 2020, 12:00:00

I have many div elements with same size but with different colors. So I created a component 'Colors.jsx' in which I have the below code


import React from "react";
import "./styles.css";

function Colors(props) {
return (
<div className="colors" style={{backgroundColor: {props.color}}}></div>
);
}

export default Colors;

The problem is I'm getting these errors:



/src/Colors.jsx: Unexpected token, expected "," (6:59)

4 | function Colors(props) {

5 | return (

6 | <div className="colors" style={{backgroundColor: {props.color}}}>

^ 7 | );

8 | }

9 |




4 | function Colors(props) {

5 | return (

6 | <div className="colors" style={{backgroundColor: {props.color}}}>

^ 7 | );

8 | }

9 |




Parsing error: Unexpected token, expected ","

4 | function Colors(props) {

5 | return (

6 | <div className="colors" style={{backgroundColor: {props.color}}}>

^ 7 | );

8 | }

9 | (null)



More From » css

 Answers
0

The issue is here:


<div className="colors" style={{backgroundColor: {props.color}}}></div>

You need to do like this(remove extra currly braces):


<div className="colors" style={{backgroundColor: props.color}}></div>

[#2718] Thursday, September 3, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
monetm

Total Points: 615
Total Questions: 103
Total Answers: 119

Location: Finland
Member since Fri, Oct 21, 2022
2 Years ago
monetm questions
;