0.0.9 • Published 2 months ago
@markusylisiurunen/optimistik v0.0.9
Optimistik
import { Optimistik, createMutation, useQuery } from "optimistik";
import React from "react";
const optimistik = new Optimistik({ name: "demo" });
const Increment = createMutation("Increment", async (tx) => {
const count = (await tx.get<number>("count")) ?? 0;
await tx.set("count", count + 1);
});
const Decrement = createMutation("Decrement", async (tx) => {
const count = (await tx.get<number>("count")) ?? 0;
await tx.set("count", Math.max(0, count - 1));
});
const App: React.FC = () => {
const { data: count } = useQuery(optimistik, async (tx) => {
return (await tx.get<number>("count")) ?? 0;
});
return (
<div>
<button onClick={() => void optimistik.send(Decrement)}>Decrement</button>
<span>{count}</span>
<button onClick={() => void optimistik.send(Increment)}>Increment</button>
</div>
);
};
export default App;
0.0.9
2 months ago
0.0.8
3 months ago
0.0.7
3 months ago
0.0.6
3 months ago
0.0.1
3 months ago
0.0.3
3 months ago
0.0.2
3 months ago
0.0.5
3 months ago
0.0.4
3 months ago
0.0.1-alpha.2
4 months ago
0.0.1-alpha.1
4 months ago
0.0.1-alpha.0
4 months ago