nandorojo / solito

🧍‍♂️ React Native + Next.js, unified.
https://solito.dev
MIT License
3.54k stars 181 forks source link

Add routeChangeMethod prop to useParam #214

Closed ebg1223 closed 1 year ago

ebg1223 commented 2 years ago

Hello! Huge fan of this lib/project. Needed a way to override useParam push vs replace route.

Current behavior is to push if param is not currently defined, otherwise replace.

If using url as state, then for optionally nullable state elements, this may not be desirable(ex. form select), where user may set their selection, unset their selection, and then set a new selection. This would create 3 route pushes, but logically to user, back button should take them to previous page. In this case, we should always replace, even if param value is null(effectively removing param).

Alternatively, if the state param controls a significant aspect of the page, user may expect back button to take them back to previous param value. In this case, we should always push(even if param exists).

If no value for routeChangeMethod is provided, then default behavior is current behavior.

This only applies to nextjs as native useParam functions essentially as normal state.

vercel[bot] commented 2 years ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
solito ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 10, 2023 at 6:35AM (UTC)
solito-app ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 10, 2023 at 6:35AM (UTC)
solito-s9oj ✅ Ready (Inspect) Visit Preview Feb 10, 2023 at 6:35AM (UTC)
with-custom-fonts ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 10, 2023 at 6:35AM (UTC)
ebg1223 commented 2 years ago

If this is a welcome addition, I would be happy to append docs with a small update and push a new commit to this branch before merging. Thanks again for all your contributions to this community. Huge fan of your work @nandorojo

nandorojo commented 2 years ago

Interesting idea. I'll look into this more closely soon!

vercel[bot] commented 1 year ago

@ebg1223 is attempting to deploy a commit to the Beatgig Team on Vercel.

A member of the Team first needs to authorize it.

ebg1223 commented 1 year ago

@nandorojo Any thoughts on this? Would love to have it in master!

nandorojo commented 1 year ago

I'll probably have to re-implement this with a separate API, but the idea is there.

nandorojo commented 1 year ago

This is now live in 2.3.0: https://github.com/nandorojo/solito/releases/tag/v2.3.0