Что не так в этом коде, почему это сбои в тестовых случаях, давая ошибку, подобные этим:
or на кнопку нажатия +10%, увеличивает прогресс правильно
Невозможно найти элемент с текстом: 10%. Это может быть потому, что текст разбит несколько элементов. В этом случае вы можете предоставить функцию для вашего сочетания текста, чтобы сделать ваш сочетание более гибким. < /P>
import React,{useState,useEffect} from "react";
function ProgressBar() {
const [barWidth,setBarWidth]= useState(10);
const decreaseWidth = () =>{
setBarWidth(prev=>{
const newWidth = Math.max(0,prev-10);
return newWidth;
});
}
const increaseWidth = () =>{
setBarWidth(prev=>{
const newWidth = Math.min(100,prev+10);
return newWidth;
});
}
const getBgColor = (value) => {
if (value < 40) return "red";
else if (value >= 40 && value< 80) return "orange";
return "green";
}
const barStyle={
height:"100%",
width:`${barWidth}%`,
backgroundColor:getBgColor(barWidth),
display:"flex",
}
return (
Progress bar
{barWidth+"%"}
-10%
+10%
);
}
export default ProgressBar;
Подробнее здесь: https://stackoverflow.com/questions/795 ... -component