#Retrieve Current WhereFilter in ListMenuItem

20 messages · Page 1 of 1 (latest)

faint stirrupBOT
#

Can I get the current WhereFilter in a ListMenuItem?

solemn iglooBOT
#

Original message from @minor carbon - Moved from #general message

vague ice
#

Hey @minor carbon

Is this in the Edit view or List view?

#

I think there are helpers for this

minor carbon
#

@vague ice In List View. All the code I find is using DocumentDrawers, but I can't out how for example the query preset gets the Wherefilter when you create new.

vague ice
#

Try the useListQuery hook

minor carbon
#

Yes, that's it. Thank you!

solemn iglooBOT
vague ice
#

My pleasure my treasure

minor carbon
#

@vague ice If I now want to manipulate the query and fetch the data. Should I initialize a new payload instance with getPayload or use the usePayloadAPI hook or is there another way to retrieve the payload instance?

vague ice
#

Is this in a client component? Because you cannot get the payload instance in there, have to use either a server action, typical fetch for REST api, or custom endpoint

#

In server components you can use the req passed into your component

minor carbon
#

In a server component I would not be able to use useListQuery I suppose.

#

Thanks again.

vague ice
#

No, but you could wrap a client component in a server component for the best of both worlds

minor carbon
#

@vague ice Server actions work for me for now. But I wonder how it would be with your example. Do you mean

<ServerComponent>
  <ClientComponent />
</ServerComponent>
```?

My ClientComponent is a Button, but in this way it is not displayed. So I probably have to wrap the button with another client component? How do I pass the query from `useListQuery` back to the server component to perform the task? In my case: create an excel file for download ? Afaik data can be passed from server component to client component, but not back again.
vague ice
#

If you need to pass it back to the server then yes, you would need s server action

#

But your hierarchy is correct