n49 / react-stars

A simple star rating component for your React projects :star:
http://developers.n49.com/react-stars/
218 stars 81 forks source link

Props.edit is always false, even when set to true. #12

Open PAK90 opened 7 years ago

PAK90 commented 7 years ago

Weird bug; the only way I can set the 'edit' prop to true is by not including it in my settings object. If I include it, even when it's set to true, it appears as false. I think it's due to this line which overrides the value to 'false' when props.edit == true, since the typeof it is not undefined.

ashishd751 commented 7 years ago

Yes , @PAK90 , i am facing a similar issue. I want to dynamically set the edit flag, bt since the flag gets overridden , i am unable to do so. Has anyone found a work-around for that ? Or, has this bug been fixed ?

knnemade99 commented 7 years ago

@PAK90 and @ashishd751 You can use property edit={undefined} for editing the react stars. And property edit={false} or edit={true} for not editing the react stars.

So that you can change the edit functionality dynamically using edit property.

raulfdm commented 7 years ago

@knnemade99 works as you said, but is it a bug, isn't it?

ashishd751 commented 7 years ago

Yes, it is a bug. And Kunal's answer is just a workaround.

On 23-Aug-2017 4:44 PM, "Raul de Melo" notifications@github.com wrote:

@knnemade99 https://github.com/knnemade99 works as you said, but is it a bug, isn't it?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/n49/react-stars/issues/12#issuecomment-324297962, or mute the thread https://github.com/notifications/unsubscribe-auth/AICJeSU8VXNvH21Eokc_Ob1BU6P42Tw4ks5sbAl4gaJpZM4LqN3i .

olegberman commented 7 years ago

Thank you - I will take a look soon.

vaibhavvv9 commented 3 years ago

<ReactStars size={40} count={4} value={rating} edit={isEdit ? undefined : false} onChange={handleRating} /> @knnemade99 I am trying to change edit conditionally using this way but it is not working. I have tried every permutation combination with undefined, true & false but it is still not working. Can you please help me ?

knnemade99 commented 3 years ago

@vaibhavvv9
Try something like

const isEditProp = isEdit ? undefiend : true;

Then use above variable in following code

<ReactStars size={40}

count={4} value={rating} edit={isEditProp} onChange={handleRating} />

In this way if isEdit is true, it will be editable and if isEdit is false, it wont be editable.