Public
Edited
Apr 12, 2024
3 forks
15 stars
Insert cell
Insert cell
Insert cell
c = import("https://esm.run/convex/react")
Insert cell
Insert cell
Insert cell
client = new c.ConvexReactClient(url)
Insert cell
Insert cell
Insert cell
counter = queryGenerator(client, "getCounter")
Insert cell
Insert cell
Insert cell
client.mutation("incrementCounter", { increment: 1 })
Insert cell
// client.mutation("resetCounter") // uncomment to reset the counter to 0
Insert cell
Insert cell
counter
Insert cell
counter * 2
Insert cell
Inputs.button("Increment", {
reduce: () => client.mutation("incrementCounter", { increment: 1 })
})
Insert cell
Insert cell
Insert cell
client.mutation("incrementCounter", { increment: "this is a string" })
Insert cell
Insert cell
queryGenerator = (client, query, args = {}) => {
const watch = client.watchQuery(query, args);
console.log(watch);
return Generators.observe((notify) => {
console.log(watch.onUpdate);
return watch.onUpdate(() => notify(watch.localQueryResult()));
});
}
Insert cell
nonReactiveQuery = async (client, query, args = {}) => {
const watch = client.watchQuery(query, args);
const cur = watch.localQueryResult();
if (cur !== undefined) return cur;
return new Promise((r) => {
const unsubscribe = watch.onUpdate(() => {
unsubscribe();
r(watch.localQueryResult());
});
});
}
Insert cell
c2 = await import("https://esm.run/convex/browser")
Insert cell
httpClient = new c2.ConvexHttpClient(url)
Insert cell
httpClient.mutation("incrementCounter", { increment: 1 })
Insert cell
httpClient.query("getCounter")
Insert cell
Insert cell
Insert cell
{
const convexClient = new c2.ConvexHttpClient(url);
return await convexClient.query("getCounter");
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more