aboutsummaryrefslogtreecommitdiff
path: root/examples/framework-react/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/framework-react/src')
-rw-r--r--examples/framework-react/src/components/Counter.css11
-rw-r--r--examples/framework-react/src/components/Counter.tsx25
-rw-r--r--examples/framework-react/src/pages/index.astro36
3 files changed, 72 insertions, 0 deletions
diff --git a/examples/framework-react/src/components/Counter.css b/examples/framework-react/src/components/Counter.css
new file mode 100644
index 000000000..fb21044d7
--- /dev/null
+++ b/examples/framework-react/src/components/Counter.css
@@ -0,0 +1,11 @@
+.counter {
+ display: grid;
+ font-size: 2em;
+ grid-template-columns: repeat(3, minmax(0, 1fr));
+ margin-top: 2em;
+ place-items: center;
+}
+
+.counter-message {
+ text-align: center;
+}
diff --git a/examples/framework-react/src/components/Counter.tsx b/examples/framework-react/src/components/Counter.tsx
new file mode 100644
index 000000000..cc416d3f1
--- /dev/null
+++ b/examples/framework-react/src/components/Counter.tsx
@@ -0,0 +1,25 @@
+import { useState } from 'react';
+import './Counter.css';
+
+export default function Counter({
+ children,
+ count: initialCount,
+}: {
+ children: JSX.Element;
+ count: number;
+}) {
+ const [count, setCount] = useState(initialCount);
+ const add = () => setCount((i) => i + 1);
+ const subtract = () => setCount((i) => i - 1);
+
+ return (
+ <>
+ <div className="counter">
+ <button onClick={subtract}>-</button>
+ <pre>{count}</pre>
+ <button onClick={add}>+</button>
+ </div>
+ <div className="counter-message">{children}</div>
+ </>
+ );
+}
diff --git a/examples/framework-react/src/pages/index.astro b/examples/framework-react/src/pages/index.astro
new file mode 100644
index 000000000..5bc1f8d36
--- /dev/null
+++ b/examples/framework-react/src/pages/index.astro
@@ -0,0 +1,36 @@
+---
+// Component Imports
+import Counter from '../components/Counter';
+const someProps = {
+ count: 0,
+};
+
+// Full Astro Component Syntax:
+// https://docs.astro.build/basics/astro-components/
+---
+
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width" />
+ <meta name="generator" content={Astro.generator} />
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
+ <style>
+ html,
+ body {
+ font-family: system-ui;
+ margin: 0;
+ }
+ body {
+ padding: 2rem;
+ }
+ </style>
+ </head>
+ <body>
+ <main>
+ <Counter {...someProps} client:visible>
+ <h1>Hello, React!</h1>
+ </Counter>
+ </main>
+ </body>
+</html>