# solid-js **Repository Path**: touchx_admin/solid-js ## Basic Information - **Project Name**: solid-js - **Description**: Solid.js 是一个用于构建用户界面的声明式、高效且灵活的 JavaScript 库 - **Primary Language**: TypeScript - **License**: MIT - **Default Branch**: main - **Homepage**: https://www.oschina.net/p/solid-js - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2022-03-11 - **Last Updated**: 2022-03-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README

SolidJS

[![Build Status](https://github.com/solidjs/solid/workflows/Solid%20CI/badge.svg)](https://github.com/solidjs/solid/actions/workflows/main-ci.yml) [![Coverage Status](https://img.shields.io/coveralls/github/solidjs/solid.svg?style=flat)](https://coveralls.io/github/solidjs/solid?branch=main) [![NPM Version](https://img.shields.io/npm/v/solid-js.svg?style=flat)](https://www.npmjs.com/package/solid-js) [![](https://img.shields.io/npm/dm/solid-js.svg?style=flat)](https://www.npmjs.com/package/solid-js) [![Discord](https://img.shields.io/discord/722131463138705510)](https://discord.com/invite/solidjs) [![Subreddit subscribers](https://img.shields.io/reddit/subreddit-subscribers/solidjs?style=social)](https://www.reddit.com/r/solidjs/) Solid is a declarative JavaScript library for creating user interfaces. It does not use a Virtual DOM. Instead it opts to compile its templates down to real DOM nodes and wrap updates in fine grained reactions. This way when your state updates only the code that depends on it runs. ### Key Features - Real DOM with fine-grained updates (No Virtual DOM! No Dirty Checking Digest Loop!). - Declarative data - Simple composable primitives without the hidden rules. - Function Components with no need for lifecycle methods or specialized configuration objects. - Render once mental model. - Fast! - Almost indistinguishable performance vs optimized painfully imperative vanilla DOM code. See Solid on [JS Framework Benchmark](https://github.com/krausest/js-framework-benchmark). - Fastest at Server Rendering in the [Isomorphic UI Benchmarks](https://github.com/ryansolid/isomorphic-ui-benchmarks/tree/updated) - Small! Completely tree-shakeable Solid's compiler will only include parts of the library you use. - Supports and is built on TypeScript. - Supports modern features like JSX, Fragments, Context, Portals, Suspense, Streaming SSR, Progressive Hydration, Error Boundaries and Concurrent Rendering. - Works in serverless environments including AWS Lambda and Cloudflare Workers. - Webcomponent friendly and can author Custom Elements - Context API that spans Custom Elements - Implicit event delegation with Shadow DOM Retargeting - Shadow DOM Portals - Transparent debugging: a `
` is just a div. ### Learn more on the [Solid Website](https://solidjs.com) and come chat with us on our [Discord](https://discord.com/invite/solidjs) ## The Gist ```jsx import { render } from "solid-js/web"; const HelloMessage = props =>
Hello {props.name}
; render(() => , document.getElementById("hello-example")); ``` A Simple Component is just a function that accepts properties. Solid uses a `render` function to create the reactive mount point of your application. The JSX is then compiled down to efficient real DOM expressions: ```js import { render, template, insert, createComponent } from "solid-js/web"; const _tmpl$ = template(`
Hello
`); const HelloMessage = props => { const _el$ = _tmpl$.cloneNode(true); insert(_el$, () => props.name); return _el$; }; render( () => createComponent(HelloMessage, { name: "Taylor" }), document.getElementById("hello-example") ); ``` That `_el$` is a real div element and `props.name`, `Taylor` in this case, is appended to its child nodes. Notice that `props.name` is wrapped in a function. That is because that is the only part of this component that will ever execute again. Even if a name is updated from the outside only that one expression will be re-evaluated. The compiler optimizes initial render and the runtime optimizes updates. It's the best of both worlds. Want to see what code Solid generates: ### [Try it Online](https://playground.solidjs.com/) ## Quick Start You can get started with a simple app by running the following in your terminal: ```sh > npx degit solidjs/templates/js my-app > cd my-app > npm i # or yarn or pnpm > npm run dev # or yarn or pnpm ``` Or for TypeScript: ```sh > npx degit solidjs/templates/ts my-app > cd my-app > npm i # or yarn or pnpm > npm run dev # or yarn or pnpm ``` This will create a minimal client-rendered application powered by [Vite](https://vitejs.dev/). Or you can install the dependencies in your own project. To use Solid with JSX (recommended) run: ```sh > npm install solid-js babel-preset-solid ``` The easiest way to get setup is add `babel-preset-solid` to your .babelrc, or babel config for webpack, or rollup: ```js "presets": ["solid"] ``` For TypeScript remember to set your TSConfig to handle Solid's JSX by: ```js "compilerOptions": { "jsx": "preserve", "jsxImportSource": "solid-js", } ``` ## Documentation Check out the [Documentation](https://www.solidjs.com/guide) website. [Examples](https://github.com/solidjs/solid/blob/main/documentation/resources/examples.md) ## Browser Support The last 2 versions of modern evergreen browsers and Node LTS. Testing Powered By SauceLabs ## Community Come chat with us on [Discord](https://discord.com/invite/solidjs) ### Contributors ### Open Collective Support us with a donation and help us continue our activities. [[Contribute](https://opencollective.com/solid)] ### Sponsors Become a sponsor and get your logo on our README on GitHub with a link to your site. [[Become a sponsor](https://opencollective.com/solid#sponsor)]