Skip to content

Commit d506e83

Browse files
committed
✨ Add directive to playground to make sure it works
1 parent 8740ad6 commit d506e83

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

playground/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { createSignal, lazy } from 'solid-js';
22
import { MetaProvider } from 'solid-meta';
33
import { createApp } from 'solid-utils';
4-
import { Router, useRoutes, RouteDefinition, Link } from 'solid-app-router';
4+
import { Router, useRoutes, Link } from 'solid-app-router';
5+
import type { RouteDefinition } from 'solid-app-router';
56

67
import test from '@@/test.txt?raw';
78
import Home from '@/index';

playground/pages/index.tsx

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
import { createRenderEffect, createSignal } from 'solid-js';
2+
import type { Accessor } from 'solid-js';
3+
4+
function model(
5+
element: HTMLInputElement,
6+
value: Accessor<[Accessor<string>, (value: string) => void]>,
7+
) {
8+
const [field, setField] = value();
9+
createRenderEffect(() => (element.value = field()));
10+
element.addEventListener('input', (e: Event & { currentTarget: HTMLInputElement }) =>
11+
setField(e.currentTarget.value),
12+
);
13+
}
14+
115
export default function Home() {
2-
return <h1>Welcome to Solid + Vite</h1>;
16+
const [name, setName] = createSignal('');
17+
return (
18+
<>
19+
<input type="text" use:model={[name, setName]} />
20+
<h1>Hello {name()}</h1>
21+
</>
22+
);
23+
}
24+
25+
declare module 'solid-js' {
26+
namespace JSX {
27+
interface Directives {
28+
model: [() => any, (v: any) => any];
29+
}
30+
}
331
}

0 commit comments

Comments
 (0)