react-native-radial-slider
react-native-radial-slider copied to clipboard
stale closure
It seems there is a problem inside of component with "stale closure". I`am use the function to provide to onComplete:
const onSlidingComplete = (newValue: number) => {
if (intervalId.current) clearInterval(intervalId.current);
const [ instance, value ] = [DEVICE_COMMANDS_INSTANCE.TEMP_SP, newValue]
const command = constructorService.commandModify(instance, value, device.deviceType)
console.log(device.state?.fan_speed)
deviceService.sendCommandAndUpdateState(
{ state: { ...device.state!, temp_sp: newValue}, command },localDevice, dispatch)
intervalId.current = deviceService.stateUpdateInterval(device._id,localDevice, dispatch , 8000)
}
"device" - object i am getting from the props or from selector
const device = useSelector(getDeviceInfo(id), _.isEqual)
The problem is: when i call onSlidingComplete - function, the device.state has an old state, even, i a checked by console.log(device.state) in the compopent and device.state in the function on onSlidingComplete - there are different values.
The problem is, that i change state of temperature in CircleSlider, trying to update main state
{ state: { ...device.state!, temp_sp: newValue}
but if change in another component, for example device.state.fan_speed - device.state inside of onSlidingComplete didnt know about that..
If i use some standard sliders from react-native - all work fine.
@6ase did you found any solution around it?
@6ase did you found any solution around it?
I changed my redux actions to update only the one of parametrs. So fo each command - i create function that is not mutate other values