Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Currying Params, or, Component Factories in Svelte

$
0
0

I have a simple Svelte component <Greet /> which takes two params:

<script lang=ts>  export let greeting: string;  export let name: string;</script><strong>{greeting}, {name}!</strong>

How do I create a function which takes a single parameter, name, and returns a new component which takes one param, greeting, and renders <Greet {greeting} {name} />? Like so:

<script lang=ts>  import { greetFactory } from './greetFactory';  const GreetMike = greetFactory('Mike');</script><GreetMike greeting="Hello" />// renders <Greet greeting="Hello" name="Mike" />// which in turn renders <strong>Hello, Mike!</strong>

In other words: How do I curry a param of a component?


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>