Closed bfanger closed 1 year ago
Re-using React hooks inside a Svelte component.
<script lang="ts"> import { useState } from "react"; import { hooks } from "svelte-preprocess-react"; const values = hooks(() => useState(0)); $: [count, setCount] = $values; </script> <div>Count: {count}</div> <button on:click={() => setCount(count + 1)}>+</button>
React renders are asynchronous, so the initial value of the store is undefined 😕 But the hooks implementation came very close to the proposed design.
Re-using React hooks inside a Svelte component.