react-native-toggle-switch icon indicating copy to clipboard operation
react-native-toggle-switch copied to clipboard

update value

Open maartenvandillen opened this issue 6 years ago • 3 comments

Hello! I would like to be able to update the value of the switch other than the initial value ("active" prop). My initial value comes from my state and when I change it I would like the component also to reflect the new value. I think it can be solved using componentDidUpdate which seems to be missing right now. I tried myself but the component got confused about its internal state and rendered incorrectly. I'm on v1.0.2.

maartenvandillen avatar Jul 04 '19 12:07 maartenvandillen

Hi @maartenvandillen ,

Thanks for the input, yes you are right, currently, we don't allow any value to update from outside during lifecycle of the component. Will update the component ASAP to allow the value changes from outside. Thanks.

prsn avatar Jul 05 '19 02:07 prsn

@prsn thanks, that would be great! Any idea when this will be added?

maartenvandillen avatar Jul 05 '19 07:07 maartenvandillen

It seems like this issue is still not solved. I solve the problem by adding a key to the toggle component to force re-render when the active state is changed.

The code would look like this:

<ToggleSwitch key={switch-state-${this.state.activeSwitch}...props/>} }

jaccanon29 avatar Mar 13 '22 10:03 jaccanon29