The Solid Choice: Exploring SolidJS for Your Next Web Development Project
Tags: solidjs, javascript, javascriptlibraries
Published: 2023-05-04 13:13:53

## What is SolidJS?


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/440gdzayzpj404mte6uu.png)


SolidJS is a declarative JavaScript library used for building UIs and web applications. However, instead of a Virtual DOM, SolidJS uses a technique called "fine-grained reactivity" to achieve efficient updates.

This means that components only re-render when their dependencies have changed, rather than re-rendering the entire tree as with a virtual DOM approach.

By avoiding the overhead of a virtual DOM, SolidJS can achieve excellent performance while still providing a simple and flexible API for building complex user interfaces.

Similar to React, Solid uses JSX to render HTML in the browser. It also uses familiar syntax for reactivity to update DOM in real-time.

Architecture & Components
Like most Javascript frameworks, SolidJS uses component architecture for modularity and reusability.

Here is a simple Solid component:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9jien7minsr0te0b3r7c.png)


You can also check out the SolidJS playground.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ibqkl5ful08ey7xx866l.png)


If you are familiar with React, you will notice that Solid components utilize JSX for implementation. The code snippet indicates that SolidJS components consist primarily of a single extensive JavaScript function that generates a blend of HTML and JavaScript code via JSX.

## What are Signals?

Signals are similar to the hooks in React. Signals are the foundation of Solid, the values they hold are updated automatically whenever any change is made to them, and this happens each time the value is changed.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4xrjykx5o5h59sg9cj1t.png)


In the above example, we use the 'create Signal'; it has two values, a getter and a setter. Both values are functions, the getter 'count' returns the current value and not the value itself. So to access the value, you have to use it as function 'count()'

List of Signals and their counterparts in React:

- **'createSignal'**; Similar to 'useState,' used to manage reactive state in a component.
- **'createEffect'**; Similar to 'useEffect,' used to manage side effects and asynchronous operations.
- **'createMemo'**; Similar to 'useMemo,' used to memoize the result of a computation.

**Lifecycle Methods**

Solid provides two primary lifecycle methods.

The onMount lifecycle runs a piece of code when the component renders initially. It is equivalent to a createEffect which does not have any dependencies.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gyynmg11dz3e26wgij3s.png)



The onCleanup function registers a callback function that will be executed when a component is unmounted or destroyed. This can be useful for cleaning up resources such as event listeners or timers created in the component.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oxme37do9bb2of2x9cqf.png)

## Control Flow Components

Solid's API has a bunch of built-q helpers to out various actions, such as looping through a list or conditional rendering.

For example, we have a <For> component that renders a list:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n8k0w91np9yaqgu33dtk.png)

_Some other helpful control flows are:_

- <Show> used to conditional render part of the view
- <Switch> used when there are more than 2 mutually exclusive conditions
- <Portal> used to insert elements in the mount node. Helpful in inserting Components outside of the page layout.

You can check the official documentation for more information and an explanation of all control flow.

## What are the downsides?

The main downside is the more miniature ecosystem and fewer documentation/blogs around the web. Hence, you have to be ready to do more yourself, аlso because of that, potentially, you will not see many jobs offers for it, and companies are reluctant to adopt it.

## Conclusion

Solid looks like an up-and-coming framework. The API is complete, and the usage of JSX simplifies component composition. It has a bright future, the community is still growing, and the discord server is quite active. You can find a lot of help there.

Ivan Todorov — Software Developer at [Lexis Solutions](https://www.lexis.solutions/)