We can easily specify default values for props in Nested.svelte
:
<script>
export let answer = 'a mystery';
</script>
If we now add a second component without an answer
prop, it will fall back to the default:
<Nested answer={42}/>
<Nested/>
App.svelte
Nested.svelte
xxxxxxxxxx
5
1
<script>
2
import Nested from './Nested.svelte';
3
</script>
4
5
<Nested answer={42}/>
Console
xxxxxxxxxx
52
1
/* App.svelte generated by Svelte v3.23.2 */
2
import {
3
SvelteComponent,
4
create_component,
5
destroy_component,
6
init,
7
mount_component,
8
noop,
9
safe_not_equal,
10
transition_in,
11
transition_out
12
} from "svelte/internal";
13
14
import Nested from "./Nested.svelte";
15
16
function create_fragment(ctx) {
Compiler options
result = svelte.compile(source, {
generate:
});xxxxxxxxxx
1
1
/* Add a <style> tag to see compiled CSS */