diff --git a/examples/framework-preact/astro.config.mjs b/examples/framework-preact/astro.config.mjs index b1c8d1150..50e8b1299 100644 --- a/examples/framework-preact/astro.config.mjs +++ b/examples/framework-preact/astro.config.mjs @@ -4,5 +4,7 @@ import preact from '@astrojs/preact'; // https://astro.build/config export default defineConfig({ // Enable Preact to support Preact JSX components. - integrations: [preact()], + integrations: [preact({ + appEntrypoint: '/src/pages/_app.tsx' + })], }); diff --git a/examples/framework-preact/src/components/Context.tsx b/examples/framework-preact/src/components/Context.tsx new file mode 100644 index 000000000..2c697bd36 --- /dev/null +++ b/examples/framework-preact/src/components/Context.tsx @@ -0,0 +1,4 @@ +import { createContext } from 'preact'; + +const noop = () => {}; +export const Context = createContext({ count: 0, increment: noop, decrement: noop }); diff --git a/examples/framework-preact/src/components/Counter.tsx b/examples/framework-preact/src/components/Counter.tsx index 61a9f9d5a..39d8ca76e 100644 --- a/examples/framework-preact/src/components/Counter.tsx +++ b/examples/framework-preact/src/components/Counter.tsx @@ -1,18 +1,16 @@ -import { h, Fragment } from 'preact'; -import { useState } from 'preact/hooks'; +import { useContext } from 'preact/hooks'; +import { Context } from './Context'; import './Counter.css'; export default function Counter({ children }) { - const [count, setCount] = useState(0); - const add = () => setCount((i) => i + 1); - const subtract = () => setCount((i) => i - 1); + const { count, increment, decrement } = useContext(Context); return ( <>
{count}- +