Skip to content

XiNiHa/solid-pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

solid-pattern

ts-pattern wrapper for Solid.

Usage

import { Match } from "solid-pattern";

type Union =
	| { type: "number"; number: number }
	| { type: "string"; string: string }
	| { type: "boolean"; boolean: boolean };

export default function Comp(props: { value: Union }) {
	return (
		<Match value={props.value}>
			{(match) =>
				match
					.when({ type: "number" }, (value) => <div>Number: {value().number}</div>)
					.when({ type: "string" }, (value) => <div>String: {value().string}</div>)
					.when({ type: "boolean" }, (value) => <div>Boolean: {value().boolean}</div>)
					.exhaustive()
			}
		</Match>
	);
}

This wrapper ensures that the JSX elements created with the Match component are memoized, so that the actual DOM elements are only created once.

About

ts-pattern wrapper for Solid

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published