Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/LXSMNSYC/solid-sfc

Experimental SFC compiler for SolidJS
https://github.com/LXSMNSYC/solid-sfc

Last synced: about 1 month ago
JSON representation

Experimental SFC compiler for SolidJS

Awesome Lists containing this project

README

        

# solid-sfc

> An experimental SFC syntax for SolidJS, extends [`solid-labels`](https://github.com/lxsmnsyc/solid-labels)

[![NPM](https://img.shields.io/npm/v/solid-sfc.svg)](https://www.npmjs.com/package/solid-sfc) [![JavaScript Style Guide](https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb)](https://github.com/airbnb/javascript)

## Install

```bash
npm install solid-sfc
```

```bash
yarn add solid-sfc
```

```bash
pnpm add solid-sfc
```

## Usage

### Basic example

```jsx
// Required for files that do not end in `.solid.(t|j)sx?`
'use solid-sfc';

let count = $signal(0);
let message = $memo(`Count: ${count}`);

effect: {
console.log(message);
};

// Export default is synonymous to "return".
export default

{message}

;
```

### ``, `` and ``

If a component accepts a property that renders an element, you can use `` to render that property's element for the component to receive. `` has a single attribute, `name` which is used to define the fragment's key in the props of that component.

```jsx


Loading...



```

Which is equivalent to

```jsx
Loading}>

```

You can use `` to render the received fragment on the component's side. `` also has the `name` attribute to pick from the props.

```jsx
/* Example.solid.jsx */
export default

/* ParentExample.solid.jsx */
import Example from './Example.solid';

export default (


Hello World




);
```

### `$props`

`$props` is a compile-time function that provides access to the component's props.

```jsx
const props = $props();

export default

{props.message}

;
```

For Typescript, you can pass a type for the generic parameter:

```tsx
interface Props {
message: string;
}

const props = $props();

export default

{props.message}

;
```

### `$view`

For TypeScript to infer SFCs correctly, you can `$view` on the render part of the code.

```tsx
// Message.solid.tsx
interface Props {
message: string;
}

const props = $props();

export default $view(

{props.message}

);

// App.solid.tsx
import Message from './Message.solid';

export default
```

## Tooling

### TypeScript

```ts
///
```

## License

MIT © [lxsmnsyc](https://github.com/lxsmnsyc)