<ComponentName> was created without expected prop 'segment'

Viewed 4920

When you create empty Svelte component (eg. ComponentName.svelte) like this:

<script>
    export let segment;
</script>

<style>
</style>

<svelte:head>
    <title>Lorem ipsum</title>
</svelte:head>

<p>lorem ipsum...</p>

you will have error:

<ComponentName> was created without expected prop 'segment'
1 Answers

This is to help you debug — you've defined a segment prop, but the consumer of the component isn't giving it a value, which is likely to be the cause of bugs. Either the consumer should provide a value — <ComponentName segment="foo"/> — or you should a) remove the prop, or b) give it a default value (which can be undefined):

export let segment = undefined;

Any of those three actions will prevent the warning from appearing.

Related