{"id":882,"date":"2022-04-29T21:40:00","date_gmt":"2022-04-29T19:40:00","guid":{"rendered":"https:\/\/nubisoft.io\/blog\/?p=882"},"modified":"2022-05-07T21:44:13","modified_gmt":"2022-05-07T19:44:13","slug":"introduction-to-solidjs","status":"publish","type":"post","link":"https:\/\/nubisoft.io\/blog\/introduction-to-solidjs\/","title":{"rendered":"Introduction to SolidJS"},"content":{"rendered":"\n<p>During NubiSoft&#8217;s <a href=\"https:\/\/nubisoft.io\/blog\/its-time-to-skill-up\/\" target=\"_blank\" rel=\"noreferrer noopener\">Skillup #2<\/a> I made an introduction to SolidJS and this post consists of all the major points I talked about.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why SolidJS?<\/h2>\n\n\n\n<p>SolidJS is JSX based web framework designed to provide performant reactivity for user interfaces. Before taking a deep dive into the features of this framework let&#8217;s look at its promises and assumptions.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/04\/image-1024x209.png\" alt=\"\" class=\"wp-image-883\" width=\"610\" height=\"124\" srcset=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/04\/image-1024x209.png 1024w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/04\/image-300x61.png 300w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/04\/image-768x157.png 768w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/04\/image-1536x314.png 1536w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/04\/image-1200x245.png 1200w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/04\/image.png 1870w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><figcaption><a href=\"https:\/\/www.solidjs.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.solidjs.com\/<\/a><\/figcaption><\/figure><\/div>\n\n\n\n<p>The main benefits of using (supposedly) SolidJS are top performance, powerful composability options, easy-to-use API, and high ergonomics. <\/p>\n\n\n\n<p>Other notable features are built-in support for fragments, portals, suspense, and more.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"248\" src=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/image-1024x248.png\" alt=\"\" class=\"wp-image-891\" srcset=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/image-1024x248.png 1024w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/image-300x73.png 300w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/image-768x186.png 768w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/image-1200x291.png 1200w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/image.png 1356w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Performance<\/h2>\n\n\n\n<p>SolidJS uses fine-grained reactivity which results in performance very close to vanilla JS and significantly better than <a href=\"http:\/\/github.com\/krausest\/js-framework-benchmark\" data-type=\"URL\" data-id=\"github.com\/krausest\/js-framework-benchmark\" target=\"_blank\" rel=\"noreferrer noopener\">other UI frameworks<\/a><a href=\"https:\/\/github.com\/krausest\/js-framework-benchmark\">.<\/a><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/04\/image-2.png\" alt=\"\" class=\"wp-image-885\" width=\"610\" height=\"339\" srcset=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/04\/image-2.png 927w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/04\/image-2-300x167.png 300w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/04\/image-2-768x427.png 768w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><figcaption> <a href=\"https:\/\/www.solidjs.com\/\">https:\/\/www.solidjs.com\/<\/a> <\/figcaption><\/figure><\/div>\n\n\n\n<p>One of the differences between Solid and React is explicit reactivity.  Lately, there has been a proposal to introduce the useEvent hook to React in order to keep the function&#8217;s identity the same between rerenders. Solid utilizes a different approach &#8211; the only things that should be reactive are tracked.<\/p>\n\n\n\n<p>Solid&#8217;s overall approach to reactivity is to wrap any reactive computation in a function, and rerun that function when its dependencies update. This enables &#8220;vanishing components&#8221; with lazy prop evaluation removing unnecessary wrappers and synchronization overhead.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">React-like API<\/h2>\n\n\n\n<p>Basic principles when creating reactive components are quite similar to React&#8217;s. <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>useState<\/code> becomes <code>createSignal<\/code><\/li><li><code>useEffect<\/code> becomes <code>createEffect<\/code><\/li><li><code>useMemo<\/code> becomes <code>createMemo<\/code><\/li><\/ul>\n\n\n\n<p>There&#8217;s also <code>createResource<\/code> that reflects the result of an async request.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/code-4-1024x759.png\" alt=\"\" class=\"wp-image-896\" width=\"602\" height=\"446\" srcset=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/code-4-1024x759.png 1024w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/code-4-300x222.png 300w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/code-4-768x569.png 768w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/code-4-1536x1139.png 1536w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/code-4-1200x890.png 1200w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/code-4.png 1624w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Not really React-like API<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">Explicit lifecycle methods<\/h4>\n\n\n\n<p>Solid gives us 3 lifecycle methods:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>onMount<\/code> &#8211; registers a method that runs after the initial render and elements have been mounted<\/li><li><code>onCleanup<\/code> &#8211; registers a cleanup method that executes on disposal or recalculation of the current reactive scope<\/li><li><code>onError<\/code> &#8211; registers an error handler method that executes when child scope errors<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Control flow<\/h4>\n\n\n\n<p>Something that I find very useful in Solid&#8217;s API is helper functions that give us more control over how elements are created. For example, we have <code>&lt;For&gt;<\/code> component that renders a list.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"462\" src=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/code1-1024x462.png\" alt=\"\" class=\"wp-image-905\" srcset=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/code1-1024x462.png 1024w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/code1-300x135.png 300w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/code1-768x346.png 768w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/code1-1200x541.png 1200w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2022\/05\/code1.png 1238w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Some other useful control flow components are: <code>&lt;Show&gt;<\/code>, <code>&lt;Switch&gt;<\/code>, <code>&lt;Match&gt;<\/code>, <code>&lt;Portal&gt;<\/code> and <code>&lt;Suspense&gt;<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s not so good?<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">Tiny support<\/h4>\n\n\n\n<p>Performing a search on <a href=\"http:\/\/npmjs.com\" data-type=\"URL\" data-id=\"npmjs.com\" target=\"_blank\" rel=\"noreferrer noopener\">npmjs.com<\/a> results in ~20000\u00a0packages found for React and just ~200\u00a0packages for Solid. For comparison, Svelte has over ~4500 packages on npm. One of the crucial factors one must take into consideration when choosing a software solution is its ecosystem; libraries, community, and overall maturity. In my opinion, this is one of the biggest issues with Solid&#8217;s usage. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Small engagement<\/h4>\n\n\n\n<p>Even though Solid&#8217;s Github <a href=\"https:\/\/github.com\/solidjs\/solid\" data-type=\"URL\" data-id=\"https:\/\/github.com\/solidjs\/solid\">repo <\/a>has almost 17k stars as of the time of writing this post, there are just 14 open issues which indicate quite small engagement from the community.  <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Risk of HDD (Hype Driven Development)<\/h4>\n\n\n\n<p>Hype Driven Development is a real danger in the world of frontend development. We&#8217;re getting constantly bombarded with new solutions that provide little to no added value. Solid is certainly an appealing solution, but only time will tell if it can become the next Svelte.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>SolidJS looks like a very promising web framework. Foundations seem solid, API is more or less complete and usage of JSX simplifies components composition. There are drawbacks, but they are mostly related to the small community. If you plan to develop your app basically from scratch that has to be as performant as possible &#8211; Solid seems like a valid option.<\/p>\n\n\n\n<p>One issue that I&#8217;ve encountered during the development of a demo project was hot reload not working at all times. However, it&#8217;s hard to say which library is to blame.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Useful links<\/h2>\n\n\n\n<p>SolidJS homepage &#8211; <a href=\"https:\/\/www.solidjs.com\/\">https:\/\/www.solidjs.com\/<\/a><\/p>\n\n\n\n<p>Article by Solid&#8217;s creator &#8211; <a href=\"https:\/\/ryansolid.medium.com\/solidjs-the-tesla-of-javascript-ui-frameworks-6a1d379bc05e\">https:\/\/ryansolid.medium.com\/solidjs-the-tesla-of-javascript-ui-frameworks-6a1d379bc05e<\/a><\/p>\n\n\n\n<p>Repo with SolidJS examples &#8211; <a href=\"https:\/\/github.com\/preacherxp\/solidjs-skillup-intro\">https:\/\/github.com\/preacherxp\/solidjs-skillup-intro<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>During NubiSoft&#8217;s Skillup #2 I made an introduction to SolidJS and this post consists of all the major points I talked about. Why SolidJS? SolidJS is JSX based web framework designed to provide performant reactivity for user interfaces. Before taking a deep dive into the features of this framework let&#8217;s look at its promises and [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":918,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_case_study_excerpt":"","footnotes":""},"categories":[73,68,3],"tags":[241,245],"class_list":["post-882","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-from-the-life-of-nubisoft","category-javascript","category-software-development","tag-skillup","tag-solidjs"],"_links":{"self":[{"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/posts\/882","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/comments?post=882"}],"version-history":[{"count":21,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/posts\/882\/revisions"}],"predecessor-version":[{"id":920,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/posts\/882\/revisions\/920"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/media\/918"}],"wp:attachment":[{"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/media?parent=882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/categories?post=882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/tags?post=882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}