Closed nandorojo closed 1 year ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
solito-app | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jun 24, 2023 3:16pm |
solito-s9oj | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jun 24, 2023 3:16pm |
Testing
We're preparing for Solito v4!
What
This PR aims to add Next.js App Directory support, bringing the best-of-both-worlds stack into a new phase.
The goals of this PR and its APIs follow the Solito philosophy you're used to: extend Next.js APIs, make them work on native, and add adjustments where they inevitably diverge.
The following changes are included:
solito/link
Link
andTextLink
components are now marked withuse client
, making them compatible with RSC and the app directory.solito/navigation
Following the Next.js approach, there is now a new import,
solito/navigation
, for the App Directory hooks. You will use this instead of other imports you may be used to, such assolito/router
foruseRouter
, andsolito
forcreateParam
.The following hooks are added:
useRouter
: Similar to theuseRouter
hook fromsolito/router
, adapted for the App Directory by following thenext/navigation
conventions. It has the same behavior on iOS and Android.useParams
: Read dynamic segment parameters (/users/[userId]
) as{ userId: string }
.useSearchParams
: Read URL search parameters using theURLSearchParams
class.usePathname
: The much-requested hook to read the current path. On native, this is only safe if you're using Expo Router. This hook may change in the future, depending on its stability on native.useUpdateSearchParams
: A convenience hook to update search parameters as an object. CallssetParams
on native, androuter.push
orrouter.replace
on Web (configurable).useLink
The same hook that exists now fromsolito/link
, adapted for the App Directory. You can call this to create accessible, custom link components.The hooks mirror Next.js as closely as possible, along with some additional typesafety.
Let's explore the usage for each hook.
useRouter
useParams
100% feature parity with the Next.js hook.
If you want to reuse the types, and you're using a sufficiently-recent version of TypeScript, you can create a custom function with the wrapped type:
useSearchParams
100% feature parity with the Next.js hook.
usePathname
100% feature parity with the Next.js hook.
Please keep in mind that this hook may not be perfectly safe to use on iOS / Android if you haven't gone all-in on using links to power navigation for React Navigation. If all screens have a linking config, then this should be safe. Expo Router users can use this hook safely.
I am looking into adding support for
usePathname
forsolito/router
too, allowing its usage in non-app directory folders.useUpdateSearchParams
A Solito hook to update search parameters.
On native,
setParams
is called. On Web