-
I'm trying to pass in additional params to my data loader. This is a param that was passed to my component directly like this:
My data loader is a simple one:
TOP_PRODUCTS_QUERY is a graphQL query where "$count" is referenced. How do I pass this variable through? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @sid2364, loaders execute before your component renders, so you cannot pass data from the component directly to the loader. This is because the components get rendered on the server (SSR), so all data needs to be fetched up front in the loaders before the page can SSR. Loaders should load data based on the request, which includes the URL and parameters within it (and cookies). I'm not entirely sure what you are trying to accomplish with this |
Beta Was this translation helpful? Give feedback.
Hi @sid2364, loaders execute before your component renders, so you cannot pass data from the component directly to the loader. This is because the components get rendered on the server (SSR), so all data needs to be fetched up front in the loaders before the page can SSR. Loaders should load data based on the request, which includes the URL and parameters within it (and cookies).
I'm not entirely sure what you are trying to accomplish with this
count
variable. If it doesn't make sense for it to be in the URL (?count=1
or something like that), you could create a resource route, which is essentially a route that has a loader and no UI. And then you can useuseFetcher()
to call the resource …