0

I'm using svelte-loadable and the below code but I'm getting the below warning and I feel this is not a good code.

Can you suggest me how to properly handle this?

The warning: <Create> was created with unknown prop 'playerID'

The code:

<script lang="ts">
    import Loadable from "svelte-loadable";
  
  export let loader: string;
  // other code
</script>

<Loadable
  loader={loader === "player"
    ? () => import("$lib/../routes/players/create.svelte")
    : () => import("$lib/../routes/teams/create.svelte")
    // others here...
  }
  let:component
>
  <svelte:component
    this={component}
    {formName}
    on:SOMETHING={handleSOMETHING}
    {/* other props here */}
    playerID={loader === "player" ? playerID : undefined}
  />
</Loadable>

Is there a way I can avoid the playerID prop based on which component I'm loading?

1 Answer 1

1

One way would be to just have an {#if} on loader and have separate Loadable/svelte:component pairs. Then you can just pass the appropriate properties.

If you do not need props with bind you could also have a local variable that contains the correct props based on loader and then spread that object. Something like:

const props = loader == 'player' ?
  { playerID } :
  {};
<svelte:component {...props} />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.