Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make component completely controllable from the parent #78

Closed
Tracked by #94
nerdyman opened this issue Oct 5, 2022 · 1 comment · Fixed by #94
Closed
Tracked by #94

Make component completely controllable from the parent #78

nerdyman opened this issue Oct 5, 2022 · 1 comment · Fixed by #94
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Milestone

Comments

@nerdyman
Copy link
Owner

nerdyman commented Oct 5, 2022

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 #64 in #48.

Option 1 - Standalone Hook

The state for the main component could be abstracted into it's own hook and exported from the library. The slider component itself would not call the hook, the parent component would instead. This would 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={} />
};

Option 2 - useimperativehandle

useimperativehandle may be a simpler option from a DX perspective as the API for v2 and v3 would remain the same but you could optionally call the hook to access the internal properties of the slider.

@nerdyman nerdyman added this to the v3 milestone Oct 5, 2022
@nerdyman nerdyman added the enhancement New feature or request label Oct 5, 2022
@nerdyman nerdyman self-assigned this Oct 18, 2022
@nerdyman nerdyman mentioned this issue Nov 12, 2022
Merged
21 tasks
@nerdyman nerdyman linked a pull request Nov 12, 2022 that will close this issue
Merged
21 tasks
@nerdyman nerdyman changed the title Make component completely controllable from the parent (resolves #64) Make component completely controllable from the parent Nov 15, 2022
@nerdyman nerdyman added awaiting release documentation Improvements or additions to documentation labels Apr 1, 2023
@nerdyman
Copy link
Owner Author

Resolved in #94

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

1 participant