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

useQueryValue composition to make working with query values that are not params just as easy #314

Merged
merged 5 commits into from
Nov 19, 2024

Conversation

pleek91
Copy link
Contributor

@pleek91 pleek91 commented Nov 17, 2024

Description

Query params are useful for route matching and declaring known route state. But sometimes the query state cannot be known ahead of time, is dynamic, or for other reasons cannot be declared on the route.

useQueryValue aims to make working with query values that are not params as feature rich as params themselves.

Working with simple values

const { value } = useQueryValue('foo')
//           ?^ Ref<string | null>

Working with arrays

const { values } = useQueryValue('foo')
//           ?^ Ref<string[]>

Using params

const { value, values } = useQueryValue('foo', Number)

value // Ref<number | null>

values // Ref<number[]>

A remove callback is also returned to make deleting query keys simple

const { value, remove } = useQueryValue('foo')

value.value = 'bar'

// ?foo=bar

remove()

// query is empty

Copy link

netlify bot commented Nov 17, 2024

Deploy Preview for kitbag-router ready!

Name Link
🔨 Latest commit 5434bcc
🔍 Latest deploy log https://app.netlify.com/sites/kitbag-router/deploys/673bff98f45a92000836b842
😎 Deploy Preview https://deploy-preview-314--kitbag-router.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@pleek91 pleek91 force-pushed the use-route-query-value branch from 739a539 to 2f5f8f1 Compare November 18, 2024 21:24
@pleek91 pleek91 marked this pull request as ready for review November 19, 2024 02:56
@pleek91 pleek91 changed the title useQueryValue composition to working with query values that are not params useQueryValue composition to make working with query values that are not params just as easy Nov 19, 2024
Copy link
Contributor

@stackoverfloweth stackoverfloweth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love this! 😍

@pleek91 pleek91 merged commit 26e5714 into main Nov 19, 2024
6 checks passed
@pleek91 pleek91 deleted the use-route-query-value branch November 19, 2024 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants