Skip to content

Commit 502b585

Browse files
authored
docs: enhance migration docs about accessors (#15138)
* docs: enhance migration docs about accessors related to #15134 * more
1 parent 7867e75 commit 502b585

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

documentation/docs/07-misc/07-v5-migration-guide.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,39 @@ If a bindable property has a default value (e.g. `let { foo = $bindable('bar') }
722722
723723
### `accessors` option is ignored
724724
725-
Setting the `accessors` option to `true` makes properties of a component directly accessible on the component instance. In runes mode, properties are never accessible on the component instance. You can use component exports instead if you need to expose them.
725+
Setting the `accessors` option to `true` makes properties of a component directly accessible on the component instance.
726+
727+
```svelte
728+
<svelte:options accessors={true} />
729+
730+
<script>
731+
// available via componentInstance.name
732+
export let name;
733+
</script>
734+
```
735+
736+
In runes mode, properties are never accessible on the component instance. You can use component exports instead if you need to expose them.
737+
738+
```svelte
739+
<script>
740+
let { name } = $props();
741+
// available via componentInstance.getName()
742+
export const getName = () => name;
743+
</script>
744+
```
745+
746+
Alternatively, if the place where they are instantiated is under your control, you can also make use of runes inside `.js/.ts` files by adjusting their ending to include `.svelte`, i.e. `.svelte.js` or `.svelte.ts`, and then use `$state`:
747+
748+
```js
749+
+++import { mount } from 'svelte';+++
750+
import App from './App.svelte'
751+
752+
---const app = new App({ target: document.getElementById("app"), props: { foo: 'bar' } });
753+
app.foo = 'baz'---
754+
+++const props = $state({ foo: 'bar' });
755+
const app = mount(App, { target: document.getElementById("app"), props });
756+
props.foo = 'baz';+++
757+
```
726758
727759
### `immutable` option is ignored
728760

0 commit comments

Comments
 (0)