вы можете проверить этот пример:
import React from "react";
export default function NumberList({numbers}) {
let color = '';
const listItems = numbers.map((n) => {
color = (n % 3 === 0)? 'skyblue' : 'lightgreen';
return <li style={{backgroundColor:`${color}`}} key={n}>{n}</li>;
});
return (
<div>
<ul>
{listItems}
</ul>
</div>
);
}
App. js
import React, {useEffect, useState} from 'react';
import NumberList from "./LIColor";
class App extends React.Component {
render() {
let numbers = [];
for (let i = 0; i < 10; i++)
numbers.push(i);
return (
<NumberList numbers={numbers}/>
)
}
}
export default App;