Skip to content

Commit 6e4c78a

Browse files
author
Julien Bouquillon
committed
docs: add counter example
1 parent a531e36 commit 6e4c78a

File tree

1 file changed

+65
-4
lines changed

1 file changed

+65
-4
lines changed

example/src/index.js

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,37 @@ const ORBIT_DB_DOCS =
1515
const ORBIT_DB_KEYVALUE =
1616
"/orbitdb/zdpuAod4qh5m3SmjuSVtLUEspqp1yCQABWm1iEdSPFDQ5mUkU/react-ortbitdb-keyvalue";
1717

18+
const ORBIT_DB_COUNTER =
19+
"/orbitdb/zdpuAzbF3ZzhMsbtw4vkKoP1BEcH1CbgE1fRMUuykQdcbHe7X/react-ortbitdb-counter";
20+
1821
const Intro = () => (
1922
<div className="jumbotron">
2023
<h1 className="display-4">react-orbitdb</h1>
2124
<p className="lead">
2225
React hooks and providers for dealing with IPFS Orbit-db datasources.
2326
</p>
2427
<hr className="my-4" />
28+
<p>
29+
On this page you can find different examples of OrbitDB databases. <br />
30+
Other visitors can also interact in real-time with the data. <br />
31+
<br />
32+
<b>No server!</b>
33+
</p>
34+
<hr className="my-4" />
2535
<a
2636
className="btn btn-outline-primary"
2737
href="https://github.com/revolunet/react-orbitdb"
2838
role="button"
2939
>
30-
See on GitHub
40+
See project on GitHub
41+
</a>
42+
&nbsp;
43+
<a
44+
className="btn btn-outline-primary"
45+
href="https://github.com/revolunet/react-orbitdb/blob/master/example/src/index.js"
46+
role="button"
47+
>
48+
This page source code
3149
</a>
3250
</div>
3351
);
@@ -153,7 +171,6 @@ const KeyValueDemo = () => {
153171
create: true,
154172
public: true,
155173
});
156-
console.log("records", records);
157174
const addKey = async () => {
158175
const [key, value] = newKeyValue();
159176
await db.put(key, value);
@@ -217,7 +234,7 @@ const EventLogDemo = () => {
217234
};
218235
useEffect(() => {
219236
if (db) {
220-
console.log("add an event on first load");
237+
// add an event on first load
221238
addEvent();
222239
}
223240
}, [db]);
@@ -236,7 +253,7 @@ const EventLogDemo = () => {
236253
</span>{" "}
237254
<button
238255
style={{ marginLeft: 10 }}
239-
className="btn btn-outline-primary"
256+
className="btn btn-outline-primary"
240257
onClick={addEvent}
241258
>
242259
Add
@@ -269,16 +286,60 @@ const EventLogDemo = () => {
269286
);
270287
};
271288

289+
const CounterDemo = () => {
290+
const { inc, value } = useOrbitDb(ORBIT_DB_COUNTER, {
291+
type: "counter",
292+
create: true,
293+
public: true,
294+
});
295+
const add = () => {
296+
inc();
297+
};
298+
return (
299+
<div>
300+
<p style={{ fontSize: "0.8em" }}>
301+
{(value && `Connected to ${ORBIT_DB_COUNTER}`) ||
302+
`Connecting to ${ORBIT_DB_COUNTER}...`}
303+
</p>
304+
{value && (
305+
<h1>
306+
<span
307+
className="badge badge-primary"
308+
style={{ fontVariantNumeric: "tabular-nums" }}
309+
>
310+
{value}
311+
</span>
312+
<button
313+
style={{ marginLeft: 10 }}
314+
className="btn btn-outline-primary"
315+
onClick={add}
316+
>
317+
Add
318+
</button>
319+
</h1>
320+
)}
321+
</div>
322+
);
323+
};
324+
272325
const App = () => (
273326
<div>
274327
<OrbitProvider>
275328
<Intro />
329+
<h2>counter</h2>
330+
<CounterDemo />
331+
<br />
276332
<h2>eventlog</h2>
277333
<EventLogDemo />
334+
<br />
278335
<h2>docstore</h2>
279336
<DocStoreDemo />
337+
<br />
280338
<h2>keyvalue</h2>
281339
<KeyValueDemo />
340+
<p>&nbsp;</p>
341+
<p>&nbsp;</p>
342+
<p>&nbsp;</p>
282343
</OrbitProvider>
283344
</div>
284345
);

0 commit comments

Comments
 (0)