Open JoeDuncko opened 3 years ago
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.
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
@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.
useMountedState and useUnmountPromise — track if component is mounted. (Implemented as useIsMounted)
we dont have useUnmountPromise
yet
Crossed out the "create" hooks, split up all the lines with "and"s.
Added links to the new useIsomorphicLayoutEffect
and useDebounceCallback
hooks
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.
This issue should now be up to date FYI.
It'd be nice to know what needs to be done to port a hook over. I'd like to port useCopyToClipboard
, but I'm not sure if it needs refactoring.
Should it keep using useSetState
? Can useSetState
be ported over as-is? It also needs to use useIsMounted
instead of useMountedState
. What else?
I wouldn't mind helping out with stories/docs so someone with more context could focus on writing/porting the hooks.
@hedgerh it can't be ported as-is since it's dependency (clipboardjs) should be listed as optional depency now (look at useCookie to see how package check implemented). Tbh I don't remember all internals and away from pc, I'll reply to you once I'll reach the laptop.
No rush. Why are these being listed as peerdeps and as optional now?
@hedgerh since very few people need these hooks - there is no need to make everyone to download them.
@xobotyi @JoeDuncko I'm wondering are going to implement the useCustomCompareEffect
|useDeepCompareEffect
hook?
@Rey-Wang working on it right now, will be published Monday I guess
This issue is now up to date.
@Rey-Wang we now have useCustomCompareEffect
and useDeepCompareEffect
!
usePreviousDistinct
done ✅
usePreviousDistinct
done ✅
I think we are missing this one in the README
EDIT: Made a PR
Can you please re-visit removing createMemo
? It's an extremely useful pattern that allows you to share a memoized function across components. https://github.com/streamich/react-use/blob/master/docs/createMemo.md
Hello, I'm first time working on open source projects. I want to start with useError :)
Hello, I finished the useError hook, but I couldn't start the storybook. I'm just wondering if it's a known issue?
yarn run v1.22.18
$ start-storybook -p 6006 --docs --no-manager-cache
info @storybook/react v6.4.22
info
info => Loading presets
info => Serving static files from ././.storybook/public at /
ERR! TypeError: (intermediate value) is not iterable
ERR! at _default (/node_modules/@storybook/builder-webpack4/dist/cjs/preview/iframe-webpack.config.js:73:22)
ERR! at processTicksAndRejections (internal/process/task_queues.js:95:5)
ERR! at async Object.start (/node_modules/@storybook/builder-webpack4/dist/cjs/index.js:91:16)
ERR! at async Promise.all (index 0)
ERR! at async storybookDevServer (/node_modules/@storybook/core-server/dist/cjs/dev-server.js:126:28)
ERR! at async buildDevStandalone (/node_modules/@storybook/core-server/dist/cjs/build-dev.js:115:31)
ERR! at async buildDev (/node_modules/@storybook/core-server/dist/cjs/build-dev.js:161:5)
ERR! TypeError: (intermediate value) is not iterable
ERR! at _default (/node_modules/@storybook/builder-webpack4/dist/cjs/preview/iframe-webpack.config.js:73:22)
ERR! at processTicksAndRejections (internal/process/task_queues.js:95:5)
ERR! at async Object.start (/node_modules/@storybook/builder-webpack4/dist/cjs/index.js:91:16)
ERR! at async Promise.all (index 0)
ERR! at async storybookDevServer (/node_modules/@storybook/core-server/dist/cjs/dev-server.js:126:28)
ERR! at async buildDevStandalone (/node_modules/@storybook/core-server/dist/cjs/build-dev.js:115:31)
ERR! at async buildDev (/node_modules/@storybook/core-server/dist/cjs/build-dev.js:161:5)
@Bailig Yes, Storybook being broken in main is a known issue. Dependabot broke something last week. Will try to fix it today. Sorry about that!
Hey guys,
I'd like to do migration from old react-use
, the only remaining bit for me is useBeforeUnload
. Do you have some estimation when will be migrated ?
thanks!
This is a relatively easy project to get involved with contributions! Maybe you'd be interested in opening a PR yourself for it?
useBeforeUnload
is easily achievable with useEventListener
hook
useEventListener(window, 'beforeunload', ()=>{ /* do your stuff here */ })
If we don't plan to implement useBeforeUnload
, maybe we should strike it from OP?
surely do, just realized just now (list been made up before useEventListener
implementation)
Overall you can make a PR with migration guide for taht hook (have not enough time for that atm)
That being said, maybe there's something to be said for NOT porting this hook if it's so easy to accomplish with useEventListener
I'll mention it in the list later
@ArttuOll could you please make a mention to migration guide about unwilling to implement useBeforeUnload
with example from above conversation?
Updated the above list to match #1004 .
While you're at it, I think useWindowSize
can be ticked off ✔️
I also ticked the ones that are not going to be implemented, so that they would also be counted as completed tasks.
What does everybody think about porting of the location-related hooks such as useHash
, useLocation
and useSearchParam
? There are quite a few routing libraries out there that also offer these hooks. Does it make sense for us to offer them as well?
Personally I think no 🤔
I agree with you.
Just been thinking about it yesterday when used react-router's hook😁 Strike them out.
Also you can strike out
It does not provide handles to start and/or stop rerendering therefore it is not the full replacement.
Better to finish the PR that we have. useRaf
as it is achievable via composition of useRerender
and useRafEffect
literally like useRafEffect(useRerender())
I presume useUpsert
will not be ported, since useList
already provides an upsert function. I ticked it on the list and created a PR (#1046) to update the migration guide.
Unless I'm missing something here, I feel like useSize
can probably be crossed off. Since there is a useMeasure
and useResizeObserver
@ArttuOll I was looking at porting over useTimeout
and useTimeoutFn
next. useTimeout
is pretty much just useRerender
on a timer. Do you think it would be best to make that hook? Or what are your thoughts on just having an optional timer on useRerender
?
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
@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.
Updated the list again.
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
.agreed on all of them
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()
@JoeDuncko can i work on useScrolling, only the test is not done
@JoeDuncko can i work on useScrolling, only the test is not done
Sure!
@JoeDuncko I would like to work on useQueue
, can I start working on it?
@JoeDuncko I would like to work on
useQueue
, can I start working on it?
Sure!
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:Hooks to port
Sensors
useHash — tracks location hash value.(No plans to implement. Instead, use one the various routing libraries available.)useKey — track keys.(Implemented as useKeyboardEvent)useKeyPress — track keys.(Implemented as useKeyboardEvent)useKeyboardJs — track keys.(Implemented as useKeyboardEvent)useKeyPressEvent — track keys.(Implemented as useKeyboardEvent)useLocation — tracks page navigation bar location state.(No plans to implement. Instead, use one the various routing libraries available.)useSearchParam — tracks page navigation bar location state.(No plans to implement. Instead, use one the various routing libraries available.)useSize — tracks an HTML element's dimensions.(UseuseWindowSize
instead)createBreakpoint — tracks innerWidth(Not planning to implement)UI
Animations
useInterval and useHarmonicIntervalFn — re-renders component on a set interval using setInterval.(Implemented asuseIntervalEffect
).useTimeout — re-renders component after a timeout.(Can be composed from other hooks, see migration guide).useTimeoutFn — calls given function after a timeout.(Implemented asuseTimeoutEffect
).Side-effects
useBeforeUnload — shows browser alert when user try to reload or close the page.(No plans to implement, address migration guide for workaround)useCopyToClipboard — copies text to clipboard.(no plans to implement - use browser's API instead)useFavicon — sets favicon of the page.(Hooks that modify theuseThrottleFn — throttles a function.useTitle — sets title of the page.(Hooks that modify theLifecycles
useEffectOnce — a modified useEffect hook that only runs once.(it's just an alias foruseMountEffect
)useLifecycles — calls mount and unmount callbacks.(no sense to port, has almost no benefit comparing touseEffect
)useUnmountPromise — track if component is mounted.(No plans to implement).usePromise — resolves promise only while component is mounted.(No plans to implement)useLogger — logs in console as component goes through life-cycles.(Implemented as useLifecycleLoggerState
createMemo — factory of memoized hooks.(Not planning to implement)createReducer — factory of reducer hooks with custom middleware.(Not planning to implement)createReducerContext — factory of hooks for a sharing state between components.(Not planning to implement)createStateContext — factory of hooks for a sharing state between components.(Not planning to implement)useDefault — returns the default value when state is null or undefined.(No plans to implement. Use useMediatedState instead).useGetSet — returns state getter get() instead of raw state.(No plans to implement)useGetSetState — as if useGetSet and useSetState had a baby.(No plans to implement)useSetState — creates setState method which works like this.setState.(No plans to implement)useNumber — tracks state of a number.(Implemented as useCounter)useUpsert — tracks state of an array.(UseuseList
instead.)useRendersCount — count component renders.(Implemented asuseRenderCount
).createGlobalState — cross component shared state.(Not planning to implement)useMethods — neat alternative to useReducer.(No plans to implement)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!