🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Is it Possible to Update the Sort Value via Params in a Client Query?

5 replies
Last updated: May 12, 2020
Is it possible to update the sort value eg:
 | order($sort) 
via params in a client query?
May 12, 2020, 10:43 AM
Params are only available in the query statement I believe (so between
), not in slice, projection, order, etc. However, nothing should stop you from using a JS variable there, if that helps?
const query = groq`*[_type == $type]{...} | order("${sort}")`
May 12, 2020, 11:04 AM
ah ok thanks! Can just use JS variables. Can I ask the benefit of using
May 12, 2020, 11:08 AM
I’m guessing variables will be important too if making pagination and updating the slice
May 12, 2020, 11:09 AM
It will work without
as well I think and yep, you would probably use vars for slices too in that situation.
May 12, 2020, 11:11 AM
May 12, 2020, 11:12 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?