Skip to content

stale closure #54

Description

@6ase

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions