SolidJSS
SolidJS4y ago
52 replies
Aaron

Solid Cache

hey @lxsmnsyc sorry to bother you. I´ve been trying your library, am I doing this correctly:

  const [queryParams, setQueryParams] = useSearchParams()

  const { data: bookings, isFetching } = createCachedResource({
    source: () => queryParams,
    key: ({ page, query }) => [page, query],
    get: async () => {
      const searchQuery =
        queryParams.query === undefined ? '' : queryParams.query
      const currentPage = queryParams.page ? Number(queryParams.page) : 1

      return await supabaseClient
        .from('bookings')
        .select(
          'booking_start, booking_end, reference, created_at, products!inner(product_name, product_id)',
          { count: 'exact' },
        )
        .eq('tenant_id', user?.user_metadata.tenant_id)
        .ilike('reference', '%' + searchQuery + '%')
        .range(
          currentPage * pageSize() - pageSize(),
          currentPage * pageSize() - 1,
        )
        .order('reference', { ascending: true })
    },
  })


I'm not really sure how key works, I see it's string based, but was wondering how to effectively use this correctly
Was this page helpful?