From 436fe821b81675f1aa6d03c30dc3a3604f8d2781 Mon Sep 17 00:00:00 2001 From: Jamie Kyle Date: Wed, 1 May 2019 12:17:21 -0700 Subject: init commit --- example/index.html | 13 +++++++++++++ example/index.tsx | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 example/index.html create mode 100644 example/index.tsx (limited to 'example') diff --git a/example/index.html b/example/index.html new file mode 100644 index 0000000..c3bc2f0 --- /dev/null +++ b/example/index.html @@ -0,0 +1,13 @@ + + + + + + + Document + + +
+ + + diff --git a/example/index.tsx b/example/index.tsx new file mode 100644 index 0000000..c967d9d --- /dev/null +++ b/example/index.tsx @@ -0,0 +1,38 @@ +import React, { useState } from "react" +import { Provider, createContainer } from "../src/unstated" +import { render } from "react-dom" + +function useCounter() { + let [count, setCount] = useState(0) + let decrement = () => setCount(count - 1) + let increment = () => setCount(count + 1) + return { count, decrement, increment } +} + +let Counter = createContainer(useCounter) + +function CounterDisplay() { + let counter = Counter.useContainer() + return ( + <> + + {counter.count} + + + ) +} + +function App() { + return ( + + +
+
+ +
+
+
+ ) +} + +render(, document.getElementById("root")) -- cgit v1.2.3