-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify Queries by passing client / Query #187
Comments
I like your idea! Especially the query builder callback ( |
Yeah, I'd also like to see this simplified syntax across all frameworks (svelte, etc) that use useQuery! |
@sgup Maybe you could add a PR to add the abridged syntax version to the core ? |
Also think this looks way more useable. import { TriplitClient, Schema as S, ClientSchema } from '@triplit/client';
import { useTriplit } from '@triplit/vue';
const schema = {
todos: {
schema: S.Schema({
id: S.Id(),
text: S.String(),
complete: S.Boolean(),
}),
},
} satisfies ClientSchema;
const client = new TriplitClient({
serverUrl: YOUR_SERVER_URL,
token: YOUR_TOKEN,
schema
});
const { useQuery } = useTriplit(client);
const { fetching, results, error, updateQuery } = useQuery(
'todos',
(q) => q.where('complete', '!=', false)
); But you can still use useQuery directly where you have to pass in the client for every function call. |
In a query like this:
In the
ClientQueryBuilder class
, why not expose the currentQ
Query and a reference to the client, so it could be simplified further to:& since
useQuery
is a react-specific hook, and thus made specifically to provide an easier/better interface over triplit, it would make sense to go further react-y and use the context/provider pattern:& in the components:
Final Diff:
The text was updated successfully, but these errors were encountered: