Fireship · @fireship

Solid in 100 Seconds

Uploaded May 16, 2022 · Length 2:32

Solid in 100 Seconds

Summary

solid framework tutorial: building fast uis with maximum control over reactivity in javascript.

  • solid framework
  • javascript framework
  • reactive ui
  • ui performance
  • javascript performance

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    solid a declarative javascript framework

  2. 0:02

    for building fast uis with maximum

  3. 0:04

    control over reactivity it was created

  4. 0:06

    by ryan carniato in 2018 and is loved by

  5. 0:09

    developers because it's both pragmatic

  6. 0:11

    and extremely performant on the surface

  7. 0:13

    it shares many similarities with react

  8. 0:15

    components are javascript functions that

  9. 0:17

    return jsx for the ui however unlike

  10. 0:19

    react there's no virtual dom it uses a

  11. 0:21

    compiler more like svelt that converts

  12. 0:23

    your code into vanilla javascript to

  13. 0:25

    bring you as close to the dom as

  14. 0:26

    possible the framework itself only

  15. 0:28

    weighs 7 kilobytes and it completely

  16. 0:30

    crushes runtime performance benchmarks

  17. 0:32

    without the need for any extra magic or

  18. 0:34

    weird hacks in your code but most

  19. 0:35

    importantly it's truly reactive a

  20. 0:38

    function component is only called once

  21. 0:40

    which means you can do unheard of things

  22. 0:41

    like you set interval predictably at the

  23. 0:44

    top level data that changes or state is

  24. 0:46

    managed with the create signal primitive

  25. 0:48

    which returns a getter and setter the

  26. 0:50

    framework will observe this data and

  27. 0:51

    surgically update its exact location in

  28. 0:53

    the dom when it changes instead of

  29. 0:55

    re-rendering the entire component again

  30. 0:57

    it's truly reactive to get started

  31. 0:59

    generate a new solid project it uses

  32. 1:02

    veet as the build tool and should look

  33. 1:03

    very familiar if you've ever used react

  34. 1:05

    define a component as a plain javascript

  35. 1:07

    function now when you define the ui with

  36. 1:09

    jsx you actually get a real dom element

  37. 1:12

    instead of some weird framework

  38. 1:13

    abstraction to add reactive state to a

  39. 1:15

    component use the create signal function

  40. 1:17

    it provides a getter and setter and

  41. 1:19

    notice how the getter is a function this

  42. 1:21

    allows the framework to observe the

  43. 1:23

    current value reactively we can easily

  44. 1:25

    create derived state by simply defining

  45. 1:27

    another function based on the original

  46. 1:29

    signal and it also provides a function

  47. 1:31

    to memoize the return value or expensive

  48. 1:33

    computations in some cases you may want

  49. 1:36

    to run code when your data changes for

  50. 1:38

    that createfact allows you to run side

  51. 1:40

    effects any signals referenced in the

  52. 1:42

    body of the function will automatically

  53. 1:44

    be subscribed to to rerun the side

  54. 1:46

    effect whenever the value changes solid

  55. 1:48

    also provides on mount and on cleanup

  56. 1:50

    functions that tap into the beginning

  57. 1:52

    and end of the component lifecycle the

  58. 1:54

    framework also goes out of its way to

  59. 1:56

    make jsx more developer friendly for

  60. 1:58

    example it has a show component to