Props value passing style differences in Svelte components

29 Views Asked by At

I saw many styles of passing a prop value in a svelte components like,

  1. <MyComponent color={"#b291ff7a"} />
  2. <MyComponent color="#b291ff7a" />
  3. <MyComponent color={value} />
  4. <MyComponent color="{value}" />

What are their differences and when should I use which one?

Just asking for clarifiction

1

There are 1 best solutions below

0
Castler Steve On BEST ANSWER

This are the main differences

<MyComponent color={"#b291ff7a"} />

  • value is passed as string.

<MyComponent color="#b291ff7a" />

  • value is passed as string also, but the component might not receive it as expected. So it is not recommended.

<MyComponent color={value} />

  • passing the value variable as it is.

<MyComponent color="{value}" />

  • passing the value of the variable as string not matter what it is.