react-range icon indicating copy to clipboard operation
react-range copied to clipboard

Injecting a new value to slider...

Open Marco-exports opened this issue 4 years ago • 2 comments

Hello, we have an application that reads all the light settings in our home, using DALI technology with RPi_HAT that can query each "ballast" that dims up/down from manual switches.

I've been trying to inject these light levels into my sliders, but can't find a way to do this once the slider has started.

Is there a simple way to inject a new value and have the slider move to that spot ?

Thank you !

Marco-exports avatar Nov 15 '20 14:11 Marco-exports

UPDATE: This was by pure chance and experimenting...

export default function Slider(props) {
   const [ballast, setBallast] = useGetAndSet(props.keys)   // from:  react-context-hook
   const [values, setValues] = useState(props.values)
   const setFinal = setBallast

   useEffect(() => {
      setValues(ballast)
   })

As we're using "react-context-hook", I had to convert the Component into a Hook function...

The useEffect is inside the "slider.js", picking up any update that comes in through the "react-context-hook" (we're using socket.io and other means to update multiple sliders on same page).

Marco-exports avatar Nov 16 '20 11:11 Marco-exports

I'm afraid I have not solved this on my own... useEffect alone does not allow me to set the slider value...

Marco-exports avatar Nov 18 '20 10:11 Marco-exports