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
We used switch where the initial state set in Redux. but when entered the data and saving in local , If i'm fetching back the details it is not behaving as expected. Below is the code we have written.
<Switch
value={this.state.address.sameas.value === 'N' ? false : true}
switchWidth={50}
switchHeight={25}
buttonWidth={25}
buttonHeight={25}
switchBorderColor={'rgba(0, 0, 0, 1)'}
activeBackgroundColor={'#009669'}
inactiveBackgroundColor={'#888888'}
buttonBorderColor={'rgba(0, 0, 0, 1)'}
buttonBorderWidth={1}
padding={false}
onChangeValue={sameas => {
address.sameas.value = sameas ? 'Y' : 'N';
this.setState({ address});
}}
/>
below is the way setting the state in redux.
sameas: {
value: 'N',
error: '',
enable: true
},
The text was updated successfully, but these errors were encountered:
hey did you find solution ?
If yes please just ignore it if not here you have a solution:
It's because that you probably have rendered your switch on start, at it's state is initailzed on start.
After that you redux state is updated and props are received to you'r component and you try to update switch but switch has state initailized on constructor.
So in other words you only need to implement componentWillReceiveProps (switch.js file) method and set state of this switch in that method.
In real word example would be:
componentWillReceiveProps(nextProps) {
this.setState({
value: nextProps.value,
transformValue: new Animated.Value(nextProps.value ? this.transformValue : this.padding), //you need to remember about that
backgroundColor: new Animated.Value(nextProps.value ? 90 : -90),//you need to remember about that
buttonBackgroundColor: new Animated.Value(nextProps.value ? 90 : -90),//you need to remember about that
})
}
and when it received props it will change its state.
Ofc you can also implement logic like shouldComponentUpdate but it's up to you. This basically works.
Regards
We used switch where the initial state set in Redux. but when entered the data and saving in local , If i'm fetching back the details it is not behaving as expected. Below is the code we have written.
<Switch
value={this.state.address.sameas.value === 'N' ? false : true}
switchWidth={50}
switchHeight={25}
buttonWidth={25}
buttonHeight={25}
switchBorderColor={'rgba(0, 0, 0, 1)'}
activeBackgroundColor={'#009669'}
inactiveBackgroundColor={'#888888'}
buttonBorderColor={'rgba(0, 0, 0, 1)'}
buttonBorderWidth={1}
padding={false}
onChangeValue={sameas => {
address.sameas.value = sameas ? 'Y' : 'N';
this.setState({ address});
}}
/>
below is the way setting the state in redux.
sameas: {
value: 'N',
error: '',
enable: true
},
The text was updated successfully, but these errors were encountered: