File tree Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Original file line number Diff line number Diff line change 1
- import { createEffect , createSignal , on } from 'solid-js'
1
+ import { createEffect } from 'solid-js'
2
2
3
3
type PossibleRef < T > = T | ( ( el : T ) => void ) | undefined
4
4
5
5
const isRefFn = < T > ( ref : PossibleRef < T > ) : ref is ( el : T | null ) => void => typeof ref === 'function'
6
6
7
+ const setRefs = < T > ( refs : PossibleRef < T > [ ] , node : T | null ) => {
8
+ for ( const ref of refs ) {
9
+ if ( isRefFn ( ref ) ) {
10
+ ref ( node )
11
+ }
12
+ }
13
+ }
14
+
7
15
export function composeRefs < T > ( ...refs : PossibleRef < T > [ ] ) {
8
- const [ node , setNode ] = createSignal < T | null > ( null )
9
- createEffect (
10
- on ( node , ( el ) => {
11
- for ( const ref of refs ) {
12
- if ( isRefFn ( ref ) ) {
13
- ref ( el )
14
- }
15
- }
16
- } ) ,
17
- )
18
- return setNode
16
+ let node : T | null = null
17
+ createEffect ( ( ) => {
18
+ setRefs ( refs , node )
19
+ } )
20
+ return ( el : T ) => {
21
+ node = el
22
+ setRefs ( refs , el )
23
+ }
19
24
}
You can’t perform that action at this time.
0 commit comments