Skip to main content
Create new
Introduction
Reactivity
Props
Logic
Events
Bindings
Lifecycle
Stores
Motion
Transitions
Animations
Easing
SVG
Actions
Classes
Component composition
Context API
Special elements
Module context
Debugging
7GUIs
Miscellaneous
App.svelte
Child.svelte
<script>
import Child from './Child.svelte'
let request = {read_by_me: false}
function fetchData() {
request.n ||= 0
request.n += 1
}
</script>

<p>
This shows how the object can be updated from either the parent or child (without loss of data assuming both mutations actually wrote to a database and the fetchData in parent actually fetched from the database and therefore had any mutation done by child). In the child, ""$: requestInput" only gets logged once — and we don't overwrite our local mutation with a stale requestInput from parent — it does not get logged again as a result of updating `request` — which is a bug I seem to be running into elsewhere (which led me to create this minimal repro.
</p>

<button on:click={fetchData}>Provide fresher Request to child</button>
<Child request={request} />
loading Svelte compiler...
/* Select a component to see its compiled code */
result = svelte.compile(source, {
generate: ,
});
/* Select a component to see its compiled code */