Closed rome-user closed 1 year ago
This makes sense. I know some (e.g. my production app at work) is still on React 17; I imagine as long as we don't call this hook it will be fine.
Some quick testing shows that indeed React 17 will simply cause use-id
to be set to nil
. I'm not sure if this is good behavior. I've considered three possibilities to handle the situation.
Let it be possibly nil
, and mention the minimum required version of React in the docstring.
Introduce helix.hooks.modern
namespace that contains wrappers for the latest hooks, slowly migrating them into helix.hooks
as needed. The namespace's docstring will indicate this is where hooks introduced after React 17 exist.
helix.hooks.modern
to helix.hooks
, that requires refactoring. If we avoid this by making e.g. helix.hooks/use-id
reference helix.hooks.modern/use-id
, then we will have two ever-growing namespaces, users will likely get confused.Delay merging this PR until most CLJS users are on React 18.
react/useId
for the time being, but this will provide better developer experience for users on older versions of React.At work, I have an React app that is being migrated to Helix. It currently uses Reagent and React 17. I find a lot of value in lowering the barriers to migration as much as possible. For this reason, I think either 3 is the best approach here. What do you think?
I think merging it is fine. We could provide a shim for it if it's not available. I'd have to play with the behavior and see how to reproduce it.
Motivation Although
gensym
already exist in Clojure, I find it useful to have this hook for two reasons:helix.hooks
namespace is nice because it has autocomplete and consistent casing with other Clojure functionsgensym
, while useful on the client-side, can cause hydration mismatchSo I went ahead and added the hook, together with a basic unit test for this hook and future wrappers over React hooks.
Caveats
useId
was introduced in React 18. This code bumps the minimum required React to version 18.