Skip to content

Commit 6c9ecb3

Browse files
committed
more docs
1 parent 46a7312 commit 6c9ecb3

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

docs/pages/docs/installation.mdx

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import { Tab, Tabs, Steps, Callout } from 'nextra-theme-docs'
2222
</Tab>
2323
</Tabs>
2424

25+
<Callout type="error" emoji="️🚫">
26+
Sveltris hasn't been published to NPM yet, so you wouldn't be able to install it
27+
</Callout>
28+
2529
### Setup plugin
2630

2731
<Tabs items={["Esbuild", "Vite", "Webpack"]}>
@@ -60,8 +64,6 @@ import { Tab, Tabs, Steps, Callout } from 'nextra-theme-docs'
6064
]
6165
}
6266
```
63-
64-
6567
</Tab>
6668
</Tabs>
6769
<Callout>

docs/pages/docs/usage/hooks.mdx

+26
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
11
# Using React Hooks
2+
3+
Sveltris allows you to use React hooks inside your Svelte component by wrapping the call inside `use`.
4+
5+
`use` returns a `readonly` svelte store that can be subscribed to by your component.
6+
7+
The value of this store is `undefined` during the initial render, so it needs to be accessed inside an `#if` block.
8+
9+
```html
10+
<script>
11+
import { useState } from 'react'
12+
import { use } from 'sveltris'
13+
14+
const counter = use(useState(0))
15+
</script>
16+
17+
{#if $counter}
18+
{@const [count, setCount] = $counter}
19+
<button on:click={() => setCount(c => c + 1)}>
20+
{count}
21+
</button>
22+
{/if}
23+
```
24+
25+
## Limitations
26+
27+
It has some limitations, for eg. you can't use hooks that depend on a parent `ContextProvider` being there in the react root. But if the `ContextProvider` isn't stateful then it can be passed as the second argument of `use`
+25
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
11
# React in Svelte
2+
3+
With Sveltris, you can use any React component inside Svelte as if it was a regular Svelte component.
4+
5+
```html
6+
<script>
7+
import Counter from './Counter?in-svelte';
8+
</script>
9+
10+
<Counter />
11+
```
12+
13+
Sveltris also maps all React and custom event handlers (`/on(.*)/`) to Svelte format, and you can set them using `/on:(.*)/` syntax.
14+
So if a component has an `onSubmit` prop, you can set it as `on:submit`
15+
16+
```html
17+
<script>
18+
import Input from './Input?in-svelte';
19+
20+
let value = '';
21+
</script>
22+
23+
<Input {value} on:change={v => value = v} />
24+
```
25+
26+
These components also _just work_ with SSR without any extra configuration required.

0 commit comments

Comments
 (0)