#implicit$FirstArg(fnQrl) throws, bu no fnQrl

4 messages · Page 1 of 1 (latest)

gray otter
#

Here is my pseudo code:

const createUseCollection = <DB>() => {
  return <P extends keyof DB>(cb: QRL<(task) => Query<P>) => {
    const store = useStore({ loading: true, value: undefined })
    useTask$((task) => {
      const query = await cb(task);
      // do something with path
    })
    return store;
  }
}

interface Database {
  user: User;
  companies: Company
}
export const useCollectionQrl = createUseCollection<Database>();
export const useCollection$ = implicit$FirstArg(useCollectionQrl);

const cmpt = component$(() => {
  // Working
  const user = useCollectionQrl(
    $(() => ({ path: 'user' }))
  );
  // Not working:  TypeError: (0 , __vite_ssr_import_2__.useCollectionQrl) is not a function
  const _user = useCollection$(() => ({ path: 'user' }))
})

Any idea why te implicit$FirstArg isn't working here ?

I'm using a higher order function so I don't have to pass the whole DB everywhere I call useCollection$

dawn cipher
#

I guess you can't use it in the file you defined it in

gray otter
#

In my real app there are in 3 different files:

  • createUseCollection
  • useCollectionQrl & useCollection$
  • component