react-compare-slider icon indicating copy to clipboard operation
react-compare-slider copied to clipboard

Make component completely controllable from the parent (resolves #64)

Open nerdyman opened this issue 3 years ago • 0 comments

The slider currently takes props like position and moves them to internal states. This is moslty fine but leads to edge cases as shown in https://github.com/nerdyman/react-compare-slider/issues/64.

The state for the main component should be abstracted into it's own hook and exported from the library. The slider component itself should not call the hook, the parent component should instead. This will allow the parent component to manipulate all state and share it with ReactCompareSlider.

E.g.

import { ReactCompareSlider, useSliderState } from 'react-compare-slider';

export const Example = () => {
  const sliderState = useSliderState();

    /** Optional override */
    const onPositionChange = (position) => {
      window.alert(position);
      sliderState.setPosition(position);
    };

  return <ReactCompareSlider {...sliderState} onPositionChange={onPositionChange} itemOne={} itemTwo={} />
};

This should be done alongside #76

nerdyman avatar Oct 05 '22 11:10 nerdyman