You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How should I set the <Rating /> component to be completely controlled? That is, the value depends completely on some state.
Because even if I don't specify the onClick and initialValue attributes, <Rating /> will set the star value on click. I need the <Rating /> component to be completely dependent on some state like const [ rate, setRate ] = useState(0).
Example:
This way the component still sets the stars that are filled when clicked, even if the rate state didn't change.
import{useState}from'react';import{Rating}from'react-simple-star-rating';constApp=()=>{const[rate,setRate]=useState(0);constisLogged=false;consthandleRate=value=>{if(!isLogged)return;// here I'm trying to prevent stars to be filled if isLogged is falsesetRate(value);};return(<RatinginitialValue={rate}onClick={handleRate}iconsCount={5}allowFraction/>);};
The text was updated successfully, but these errors were encountered:
How should I set the
<Rating />
component to be completely controlled? That is, the value depends completely on some state.Because even if I don't specify the
onClick
andinitialValue
attributes,<Rating />
will set the star value on click. I need the<Rating />
component to be completely dependent on some state likeconst [ rate, setRate ] = useState(0)
.Example:
This way the component still sets the stars that are filled when clicked, even if the
rate
state didn't change.The text was updated successfully, but these errors were encountered: