Skip to content

Commit

Permalink
fix: use a prop instead of multi-return to expose the count, because …
Browse files Browse the repository at this point in the history
…it isn't working with solid-start for some reason
  • Loading branch information
trusktr committed Nov 17, 2021
1 parent c2a8cd8 commit 35c3426
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/components/Counter.tsx
@@ -1,13 +1,16 @@
import { createSignal } from "solid-js";
import { createEffect, createSignal } from "solid-js";
import "./Counter.css";

export default function Counter() {
export default function Counter(props) {
const [count, setCount] = createSignal(0);

return [
count,
createEffect(() => {
if (props.onCount) props.onCount(count())
})

return (
<button class="increment" onClick={() => setCount(count() + 1)}>
Clicks: {count}
</button>
];
);
}
7 changes: 4 additions & 3 deletions src/pages/index.tsx
@@ -1,13 +1,14 @@
import { createSignal } from "solid-js";
import Counter from "~/components/Counter";
import "./index.css";

export default function Home() {
const [count, counterButton] = <Counter />
const [count, setCount] = createSignal(0)

return (
<main>
<h1>Hello 3D world! {count}</h1>
{counterButton}
<h1>Hello 3D world! {count}</h1><br />
<Counter onCount={setCount}/>
<p>
Visit{" "}
<a href="https://solidjs.com" target="_blank">
Expand Down

0 comments on commit 35c3426

Please sign in to comment.