You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/routes/reference/jsx-attributes/use.mdx
+11-9Lines changed: 11 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,33 +3,35 @@ title: use:*
3
3
order: 5
4
4
---
5
5
6
-
These are custom directives. In a sense this is just syntax sugar over ref but allows us to easily attach multiple directives to a single element. A directive is a function with the following signature:
6
+
Custom directives attach reusable behavior to DOM elements, acting as syntactic sugar over `ref`. They’re ideal for complex DOM interactions like scrolling, tooltips, or resizing, which are cumbersome to repeat in JSX.
7
+
8
+
A directive is a function with the following signature
7
9
8
10
```ts
9
-
function directive(element:Element, accessor:() =>any):void
11
+
function directive(element:HTMLElement, accessor:Signal<any>):void
10
12
```
11
13
12
14
DirectivefunctionsarecalledatrendertimebutbeforebeingaddedtotheDOM. Youcandowhateveryou'd like in them including create signals, effects, register clean-up etc.
0 commit comments