Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Changing kwargs does not re-run use_query? #287

Answered by Archmonger
dickermoshe asked this question in Problem
Discussion options

I have a simple text input to search products

async def get_products(q: str):
 if not q:
 return Product.objects.none()
 return await database_sync_to_async(lambda: Product.objects.filter(name__icontains=q))()
@component
def textbox(recipient: str):
 text, set_text = use_state("")
 result = hooks.use_query(get_products, {"q": text})
 ...

However when the search text changes, the query is not ran again.
Shouldn't the query be reran when the kwargs change?
If not, how would I do this?

You must be logged in to vote

use_query does not automatically re-run if kwargs have changed.

In order to re-run it, you must call query.refetch().

@component
def textbox(recipient: str):
 text, set_text = use_state("")
 result = hooks.use_query(get_products, {"q": text})
 
 def on_submit(event):
 set_text(event["target"]["value"])
 result.refetch()
 ...

Replies: 1 comment

Comment options

use_query does not automatically re-run if kwargs have changed.

In order to re-run it, you must call query.refetch().

@component
def textbox(recipient: str):
 text, set_text = use_state("")
 result = hooks.use_query(get_products, {"q": text})
 
 def on_submit(event):
 set_text(event["target"]["value"])
 result.refetch()
 ...
You must be logged in to vote
0 replies
Answer selected by Archmonger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /