Been using @reactjs for years, here is how @sveltejs code is different from @reactjs

1️⃣ Stateless Component ImageImage
2️⃣ Fragment

😍 You don't need a Fragment to group multiple elements in @sveltejs ImageImage
3️⃣ Inline styles

🙆‍♂️ You can extend and manipulate the style object in @reactjs
🙅‍♂️ It's a bane to copy the styles from the DOM into the code after tweaking it in the browser devtools
😍 So much easier when you can just copy the inline styles from browser into your code. ImageImage
4️⃣ className

🙅‍♂️ className instead of class somehow confuses new web devs that `className` is a html attribute (similarly, htmlFor 🙈)
😍 So much easier to conditionally add class names to element in @sveltejs ImageImage
5️⃣ Expressions

📝 {} for embedding expressions in JSX
📝 {} for embedding data in @sveltejs template

😜 It's the same! ImageImage
6️⃣ dangerouslySetInnerHtml

🙆‍♂️ It feels more dangerous in @reactjs to inline data as html
🙅‍♂️ Somehow you always need a element container to set innerHtml in @reactjs 😅
😍 You can insert HTML anywhere with {@\html} ImageImage
7️⃣ ref

📝 in @reactjs, you use ref to get the reference of a DOM node / component instance
👉 ref.current to get the reference

📝 in @sveltejs, you use `bind:this` to bind the reference to a variable ImageImage
8️⃣ props

📝 in @reactjs, functional component's props is passed in via arguments
📝 in @sveltejs, you use `export` to define props

🤔 in the example, Component has 2 props, `value` and `max`, and max has a default value of 5. ImageImage
9️⃣ rest and spread props

📝 in @reactjs, you use rest destructuring `...` to get the rest of the props, and spread operator `...` to spread an object into props

📝 the rest of the props is available as the magic global `$$restProps` ImageImage
1️⃣0️⃣ state

📝 @reactjs useState hook returns the state and a setter to sets the state
📝 in @sveltejs you declare a variable as the state, update the variable directly to update the state ImageImage
1️⃣1️⃣ Derived state

📝 In @reactjs, you can have a state derived from another state, and if the operation is expensive, useMemo to memoise the operation

📝 In @sveltejs, you can reactively declare a variable, whose value will be reactively updated based on its dependency ImageImage
1️⃣2️⃣ Logic - conditional rendering

📝 In @reactjs, you ternary expression or logical and (&&) short circuit to conditionally render elements
📝 In @sveltejs, you use the {#\if} logic block ImageImage
1️⃣3️⃣ Logic - list rendering

📝 In @reactjs , you use .map over an array to repeat elements
📝 In @sveltejs , you use the {#\each} logic block

✨ you can object destructure items of the array easily ImageImage
1️⃣4️⃣ Logic - list rendering

📝 In @reactjs, you add the key attribute in the mapped elements to help react identify which items have changed, added or removed
📝 in @sveltejs, you add a add a bracket (...) inside the {#\each} block ImageImage
1️⃣5️⃣ Logic - asynchronous rendering

📝 In @reactjs, to asynchronously wait for a promise, to rendering loading state, and result / error state, you'll have to manage through states, or abstract them out into a custom hook
📝 In @sveltejs, you can manage them through {#\await} ImageImage

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Tan Li Hau 🤔

Tan Li Hau 🤔 Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @lihautan

1 Jul
HTML doesn't have a way of expressing logic, like conditionals and loops. @sveltejs does.

Let's take a look at the 1st logic block in @sveltejs, 👉 {#if} 👈

👇🧵 [THREAD]
If you prefer watching video, the following thread is a summary from my @YouTube video
💡{#if} is our 1st logic logic block in @sveltejs
💡it allow us to conditional render content
💡if comes with else, else if, just like you would expect in JavaScript <script>   let value = 42; ...
Read 8 tweets
29 Jun
How do you pass dynamic data when you forward slots in @sveltejs?
Let's recap, here is how you forward slots
and here is how you pass dynamic data into slots

Read 11 tweets
15 Aug 20
Another week on #CSSpodcast, this weeks topic is CSS Functions 😍

🧵
CSS Functions provides runtime contextual expressions that return dynamic real-time value per the state of the browser per user in that moment
- global space, no need import
- can be nested, calc(var(--var))
- typed, eg: `rotate(45px)` will not work
- keep the function live, recompute on value changes and updates
- many of them are pure functions, however, counter-example: `counter()`
Read 20 tweets
12 Jul 20
In the latest episode #CSSpodcast, @Una and @argyleink shared a ton of pseudo-classes

(I managed to note down 3️⃣9️⃣ of them 😱)

🧵 Here is a thread of what were shared in the podcast 👇👇👇
Pseudo-classes are selectors, lets you apply style to element based on info outside of the doc tree:

🌎 meta information, eg: language, history of navigator
☑️ state of the element, eg: checked, active, disabled

✨Pseudo-classes are great for implementing micro-interactivity
🔤 Case-insensitive
⏹ No whitespace in between
Read 24 tweets
1 Jul 20
Learned a ton of pseudo elements, that i didnt know existed, in this week's #CSSpodcast by @Una and @argyleink

thecsspodcast.libsyn.com/014-pseudo-ele…

Learn about 9️⃣ things I learned in the thread 👇👇
1️⃣

pseudo elements has 2 colons in front ::
🆚
pseudo class which have 1 colon in front :
2️⃣

::before and ::after targets the pseudo-element that is the 1st child and last child of the element respectively

📝 to create the pseudo-element, use `content` property
📝 content will be read by screen reader
📝 cannot be used by replaced elements, eg: <img>, <video>
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(