šŸ‘‹ Next.js Conf 2024: Come build, party, run, and connect with us! See all events

Discussion on how to create a search function in a custom movie app using Next.js and Sanity.io.

26 replies
Last updated: Nov 29, 2022
Is it possible to make a search query entered by the User, in my custom movie based app (not the one used as a template) ?
Nov 28, 2022, 9:24 AM
It is! You can pass in a variable using params. For example:
const query = `*[_type == 'movie' && title = $title]
const params = { title: <user-entered-term-here> }

const results = await client.fetch(query, params)
Nov 28, 2022, 6:07 PM
user M
I am not sure, how will I be able to take user input and pass it through query.
Nov 28, 2022, 6:09 PM
I am still a beginner
Nov 28, 2022, 6:09 PM
Are you using vanilla javascript or a framework for your frontend?
Nov 28, 2022, 6:09 PM
Ohh it's Next the best
Nov 28, 2022, 6:10 PM
Great! You'll need to create a controlled form that will allow you to hold whatever value the user enters in state. Then you can pass that variable to your params.
Nov 28, 2022, 6:12 PM
Ohh
user M
that was great explanation, I will get back to you if I am facing any issues but huge Thanks
Nov 28, 2022, 6:13 PM
Excellent! Best of luck!
Nov 28, 2022, 6:16 PM
user M
Are there any examples regarding this problem statement, I am still not sure what to write and where to write.
Nov 28, 2022, 6:29 PM
I don't think anyone has put together a guide for this particular use case. Can you share the code in your frontend where you'd like to add this?
Nov 28, 2022, 6:46 PM
Ohh sure
Nov 28, 2022, 6:47 PM
user M
I want to make search function here for the whole dataset.
Nov 28, 2022, 6:48 PM
Thanks! I'll be able to pick this back up in a bit šŸ™‚
Nov 28, 2022, 6:49 PM
Sure sir
Nov 28, 2022, 6:52 PM
user M
Did you got some time to making my project better
Nov 29, 2022, 12:07 PM
??
Nov 29, 2022, 12:07 PM
Nope, it was unfortunately a very busy day in the community yesterday. I'll try to take a look today.
Sidenote: I'm guessing you used 'sir' to be polite, but my pronouns are listed in my Slack name (feminine or gender neutral). I'm assuming this was an accident, but please don't misgender people in the community.
Nov 29, 2022, 4:17 PM
user M
Ohh I am really sorry, It was a mistake, don't mind me.šŸ˜”
Nov 29, 2022, 4:27 PM
I figured that was the case! Just wanted to give you a heads up šŸ™‚
Nov 29, 2022, 4:27 PM
Sorry Ma'am
Nov 29, 2022, 4:28 PM
It would be great if you pls take a look at it.
Nov 29, 2022, 4:29 PM
Will do! Just have to wrap up my morning meetings, then I'll be able to take a look.
Nov 29, 2022, 4:30 PM
It looks like you got some help in this thread. Did that answer your original question? Are you just looking for help with this question now?
Nov 29, 2022, 6:59 PM
Yes I do got the required the help
user M
Nov 29, 2022, 7:01 PM
Great! I'll follow up in that new question in a couple of minutes!
Nov 29, 2022, 7:02 PM

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?