Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 39 ยท Getting Started

Setting Up and Your First SolidJS App

Create a SolidJS project with the official templates, understand every file in it, and learn how render mounts a component and returns a dispose function.

You can try Solid in two ways: drop a script into an HTML page, or create a Vite project with a compiler for JSX. For learning here we use the first, because it runs on this page. For real applications you use the second. This lesson shows both and explains what each file of a new project does.

Creating a project

The official starter templates live in the solidjs/templates repository and are copied with degit. You need Node.js 18 or newer.

Terminal
# JavaScript
npx degit solidjs/templates/js my-app

# TypeScript
npx degit solidjs/templates/ts my-app

cd my-app
npm install
npm run dev

Vite starts a dev server, usually on http://localhost:5173. Edits appear instantly through hot module replacement, and Solid keeps component state across many edits.

If you want routing, server rendering and API routes from the start, create a SolidStart project instead (npm create solid@latest). The plain Vite template is the best way to learn the core library, and you can move to SolidStart later without relearning anything.

What is in the template

TEXT
my-app/
  index.html          page shell with <div id="root"></div>
  package.json        solid-js, vite, vite-plugin-solid
  vite.config.js      registers the Solid plugin
  src/
    index.jsx         entry point: calls render()
    App.jsx           your root component
    index.css

The two files that matter most are the Vite config and the entry point.

JavaScript
// vite.config.js
import { defineConfig } from "vite";
import solid from "vite-plugin-solid";

export default defineConfig({
  plugins: [solid()],
});

vite-plugin-solid runs babel-preset-solid, the compiler that turns JSX into direct DOM instructions. Without it, JSX in a .jsx file would not work.

JSX
// src/index.jsx
import { render } from "solid-js/web";
import App from "./App";

render(() => <App />, document.getElementById("root"));

In a TypeScript project, tsconfig.json needs two lines so the editor understands Solid's JSX types:

JSON
{
  "compilerOptions": {
    "jsx": "preserve",
    "jsxImportSource": "solid-js"
  }
}

Use "preserve", not "react-jsx": TypeScript must leave the JSX alone so the Solid compiler can transform it.

Your first component

A component is a function that returns JSX and has a name starting with a capital letter.

JSX
// src/App.jsx
function Greeting(props) {
  return <h1>Hello, {props.name}!</h1>;
}

export default function App() {
  return (
    <main>
      <Greeting name="Ada" />
      <Greeting name="Linus" />
    </main>
  );
}

Here is the same program as a live example. Instead of JSX it uses the html helper, where a component is inserted with <${Greeting} ... />.

Two components and a root

How render works

render(fn, element) does three things: it creates a reactive root, runs your function once inside it, and inserts the result into the element. It also returns a dispose function that removes everything it created and stops all effects.

In JSX you pass a function, () => <App />, not an element. Solid needs to run your code inside its own root so that signals and cleanup attach to the right owner. Passing an already-built element would run it too early.

Mount and dispose

Press Mount: the component appears and logs "tick" every second. Press Dispose: the paragraph disappears, the onCleanup callback runs, and the timer stops. This ownership idea runs through all of Solid, and Ownership and Cleanup covers it fully.

Building for production

Terminal
npm run build     # outputs optimized files to dist/
npm run preview   # serves dist/ locally to check it

The build output is static HTML, JavaScript and CSS, so any static host can serve it. The library itself adds only a few kilobytes because the compiler does most of the work ahead of time.

Common first-day mistakes

  • Lowercase component names. <greeting /> is treated as an HTML tag. Always capitalize components.
  • Forgetting the plugin. If the browser shows a raw JSX syntax error, vite-plugin-solid is missing from vite.config.
  • Passing an element to render. Write render(() => <App />, root), not render(<App />, root).
  • Using React's TypeScript setting. Keep "jsx": "preserve" with "jsxImportSource": "solid-js".

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which tool turns JSX into DOM instructions in a Vite project?

    vite-plugin-solid runs the Solid Babel preset that compiles JSX. Browsers cannot run JSX directly.
  2. 2. What does render() return?

    Calling the returned function removes the created DOM and runs cleanups for the whole root.
  3. 3. Why do you write render(() => <App />, el) instead of render(<App />, el)?

    Passing a function lets Solid call it within the root so signals, effects and cleanups have a proper owner.
  4. 4. Which tsconfig value is correct for Solid?

    TypeScript must keep the JSX untouched and use Solid's JSX types; the Solid compiler does the transform.

Summary

  • Start a project with npx degit solidjs/templates/js my-app, then npm install and npm run dev.
  • vite-plugin-solid compiles JSX; TypeScript uses jsx: preserve and jsxImportSource: solid-js.
  • Components are capitalized functions returning JSX.
  • render(() => <App />, element) mounts the app and returns a dispose function.
  • The html helper in these lessons is a build-free stand-in for JSX.

Next: How Solid Works