Skip to content

Commit 47439a7

Browse files
committed
Add useRayInstance hook for getting or creating Ray instance
1 parent c384306 commit 47439a7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { RayWithElementOptions, UseRayOptions } from '@/types';
2+
import { Ray } from 'node-ray';
23
import { ray } from 'node-ray/web';
34
import { RefObject, useEffect, useRef } from 'react';
45

@@ -11,7 +12,15 @@ export const useRay = (value, options: UseRayOptions = { replace: false, type: '
1112
}
1213

1314
rayRef.current[options.type ?? 'json'](value);
14-
}, [value]);
15+
}, [ value ]);
16+
};
17+
18+
export interface UseRayInstanceProps {
19+
instance?: Ray;
20+
}
21+
22+
export const useRayInstance = ({ instance = ray() }: UseRayInstanceProps) => {
23+
return instance || ray();
1524
};
1625

1726
export const useRayWithElement = (ref: RefObject<HTMLElement>, deps: any[] = [], options: RayWithElementOptions = { replace: true }) => {

0 commit comments

Comments
 (0)