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

Port remaining hooks from react-use #33

Open
JoeDuncko opened this issue May 2, 2021 · 58 comments
Open

Port remaining hooks from react-use #33

JoeDuncko opened this issue May 2, 2021 · 58 comments
Assignees
Labels
✨ enhancement New feature or request good first issue Good for newcomers 🆘 help wanted Extra attention is needed 🎂 new hook New hook added

Comments

@JoeDuncko
Copy link
Contributor

JoeDuncko commented May 2, 2021

Our goal with @react-hookz/web is to give the react community a general-purpose React hooks library built with care.

We'd like to port the remaining hooks from react-use (the project @react-hookz/web grew out of) while keeping in mind our tenants:

  • General-purposeness (hooks should fulfill a wide array of use cases)
  • Composability (a preference for hooks that are useful for building other hooks)
  • No or very few dependencies
  • SSR compatibility
  • 100% test coverage (ideally)
  • Concrete example use cases

Hooks to port

Sensors

UI

  • useAudio — plays audio and exposes its controls.
  • useClickAway — triggers callback when user clicks outside target area. (Implmented as useClickOutside)
  • useCss — dynamically adjusts CSS.
  • useDrop — tracks file, link and copy-paste drops.
  • useDropArea — tracks file, link and copy-paste drops.
  • useFullscreen — display an element or video full-screen.
  • useSlider — provides slide behavior over any HTML element.
  • useSpeech — synthesizes speech from a text string.
  • useVibrate — provide physical feedback using the Vibration API.
  • useVideo — plays video, tracks its state, and exposes playback controls.

Animations

  • useRaf — re-renders component on each requestAnimationFrame.
  • useInterval and useHarmonicIntervalFn — re-renders component on a set interval using setInterval. (Implemented as useIntervalEffect).
  • useSpring — interpolates number over time according to spring dynamics.
  • useTimeout — re-renders component after a timeout. (Can be composed from other hooks, see migration guide).
  • useTimeoutFn — calls given function after a timeout. (Implemented as useTimeoutEffect).
  • useTween — re-renders component, while tweening a number from 0 to 1.
  • useUpdate — returns a callback, which re-renders component when called. (Implemented as useRerender)

Side-effects

Lifecycles

State

Miscellaneous

Join our community!

Have a question? Create a discussion on GitHub or join our Discord community.

Interested in contributing code? Check out our contribution guide. We are excited to see your pull request!

@JoeDuncko JoeDuncko added ✨ enhancement New feature or request 🆘 help wanted Extra attention is needed good first issue Good for newcomers 🎂 new hook New hook added javascript labels May 2, 2021
@xobotyi
Copy link
Contributor

xobotyi commented May 2, 2021

To be clear - not all hooks will be ported, as for me - i'm against of transfering all create* hooks. And its not the only example.

@JoeDuncko
Copy link
Contributor Author

To be clear - not all hooks will be ported, as for me - i'm against of transfering all create* hooks. And its not the only example.

Definitely! Should we make a list of all the hooks that we don't want ported? Then I can cross them out above. @xobotyi

@xobotyi
Copy link
Contributor

xobotyi commented May 2, 2021

@JoeDuncko its hard to say rn, im reviewing the hooks on the go and currently refactoring (the full cycle refactoring, meaning reimplementing them from the scratch) hooks im currently using at my job, as this is easiest way for me, as i have little expertise in other areas.

@xobotyi
Copy link
Contributor

xobotyi commented May 2, 2021

useMountedState and useUnmountPromise — track if component is mounted. (Implemented as useIsMounted)

we dont have useUnmountPromise yet

@JoeDuncko
Copy link
Contributor Author

Crossed out the "create" hooks, split up all the lines with "and"s.

@JoeDuncko
Copy link
Contributor Author

Added links to the new useIsomorphicLayoutEffect and useDebounceCallback hooks

@axelboc
Copy link
Contributor

axelboc commented May 19, 2021

Thank you so much for starting this repo and leading this huge migration work! 🍻

Just wondering what the reasoning is for not migrating the create* utilities, and particularly createMemo. In my project, I have a good number of utility functions that loop over very large arrays, so it's important that they are memoised with useMemo. With createMemo I don't have to create hooks with the same signature as the utility functions, so it's really convenient and avoids a lot of duplication (especially since I use TypeScript).

I should add that I can't just turn all of my utility functions into hooks with useMemo inside them, as I use some of them inside loops. I need both the hook and non-hook versions.

@JoeDuncko
Copy link
Contributor Author

This issue should now be up to date FYI.

@xobotyi
Copy link
Contributor

xobotyi commented Dec 11, 2022

I can't see the sense of porting useTimeout but useTimeoutCallback would be pretty much handy one, since it could be well composed with other hooks

@jpwallace22
Copy link
Contributor

@xobotyi I was about to do it, but it looks like there is already a useTimeoutEffect that does it. Might want to check the box.

@ArttuOll
Copy link
Contributor

Updated the list again.

ArttuOll added a commit that referenced this issue Dec 22, 2022
…oks and check porting approval

The aim of this change is to reduce the number of cases where a PR for a new hook is submitted, but
the code is rejected, because the hook has no valid use-case or has not been approved for porting
from react-use.

re #33
ArttuOll added a commit that referenced this issue Dec 22, 2022
The aim of this section is to reduce the number of incidences where a PR for porting a new hook from
react-use is submitted and rejected because the hook has no valid use-case or has not been approved
for porting

re #33
ArttuOll added a commit that referenced this issue Dec 22, 2022
…w hooks (#1060)

* docs(New hook PR template): Add section for valid use-case for new hooks, check that hooks ported from react-use are approved for porting

* docs(CONTRIBUTING.md): Add a section on porting hooks from react-use

The aim of these changes is to reduce the number of cases where a PR for a new hook is submitted, but
the code is rejected, because the hook has no valid use-case or has not been approved for porting
from react-use.

re #33
@ArttuOll
Copy link
Contributor

Ticked off usePromise, which will not be implemented, as decided in #1048 . Also ticked off useLogger, which has been implemented as useLifecycleLogger and useRendersCount which has been implemented as useRenderCount.

What does everybody think about porting of the following hooks:

  • useUnmountPromise - Probably should not be ported, because it's almost the same as usePromise.
  • useShallowCompareEffect - We already have useDeepCompareEffect and useCustomCompareEffect. Could be easily implemented.
  • useGetSet - Could be useful for some functional programming stuff, but you could easily wrap the state setter into a function yourself (value: A) => setState(value). Also the examples in react-use for this hook make it seem that this hook could be replaced with just functional state updates.
  • useSetState - I feel like this hook is unsuitable for modern React (it emulates this.setState of class-based components).
  • useMethods - Slight syntactic sugar over useReducer.

@xobotyi
Copy link
Contributor

xobotyi commented Dec 23, 2022

agreed on all of them

@tansanDOTeth
Copy link

tansanDOTeth commented Jun 23, 2023

For useTween, I would like to make a suggestion to the API. It would be helpful if it can return a start function to grant control over when to start the tweening process.

const [t, start, stop, restart] = useTween()

@Frankcaozas
Copy link

Frankcaozas commented Jul 14, 2023

@JoeDuncko can i work on useScrolling, only the test is not done

@JoeDuncko
Copy link
Contributor Author

@JoeDuncko can i work on useScrolling, only the test is not done

Sure!

@malavshah9
Copy link

@JoeDuncko I would like to work on useQueue, can I start working on it?

@JoeDuncko
Copy link
Contributor Author

@JoeDuncko I would like to work on useQueue, can I start working on it?

Sure!

@xobotyi
Copy link
Contributor

xobotyi commented Sep 7, 2023

@JoeDuncko dang it! we already have a queue hook, but it is missing from hooks listing🤦‍♂️

@JoeDuncko
Copy link
Contributor Author

@JoeDuncko dang it! we already have a queue hook, but it is missing from hooks listing🤦‍♂️

@xobotyi Ah crap, I can knock that out if no one else does tomorrow.

@malavshah9
Copy link

@JoeDuncko @xobotyi
I was just looking to work on useCopyToClipboard, but then found this discussion where we have concluded that it is not needed at the moment. Can we remove this from this list also, if we don't want to build it.

@malavshah9
Copy link

@JoeDuncko @xobotyi
Moreover, I am looking to work on useSpeech with the following definition, is this fine or do we want to improve here?

type SpeechOptions = {
  lang: string;
  voice?: SpeechSynthesisVoice;
  rate: number;
  pitch: number;
  volume: number;
};
export type VoiceInfo = Pick<SpeechSynthesisVoice, 'lang' | 'name'>;

export type ISpeechState = SpeechOptions & {
  isPlaying: boolean;
  status: string;
  voiceInfo: VoiceInfo;
};

enum Status {
  init,
  play,
  pause,
  end,
}

const useSpeech = (text: string, options: ISpeechOptions): ISpeechState

Same as we have in react-use

@xobotyi
Copy link
Contributor

xobotyi commented Sep 11, 2023

@malavshah9 sold!

@malavshah9
Copy link

@xobotyi I wanted to work and port below mentioned hooks:

  1. useIdle
  2. useRaf
  3. useGeolocation
  4. useStateList

@xobotyi
Copy link
Contributor

xobotyi commented Oct 5, 2023

@malavshah9 it would be way better if youll help with tests migration so we can switch towards react 18

#1377

I will update that PR so it is containing only tests changes without, and after that youll be able to migrate tests

@arjunindia arjunindia mentioned this issue Oct 5, 2023
8 tasks
@malavshah9
Copy link

@xobotyi I would love to do that. Should I start migrating that for each hooks and giving you separate PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request good first issue Good for newcomers 🆘 help wanted Extra attention is needed 🎂 new hook New hook added
Development

No branches or pull requests