UNPKG

744 BJavaScriptView Raw
1import { useRef } from 'react';
2let idCount = 0;
3
4function uniqueId(prefix) {
5 return '' + ((prefix == null ? '' : prefix) + ++idCount);
6}
7
8export function notify(handler, args) {
9 // eslint-disable-next-line prefer-spread
10 if (handler) handler.apply(null, args);
11}
12export const useInstanceId = (otherId, suffix = '') => {
13 const id = useRef();
14 if (!id.current) id.current = uniqueId('rw_');
15 return (otherId || id.current) + suffix;
16};
17/**
18 * Allows for defering popup rendering untill the widget is focused,
19 * or has been opened (in order to not remove it suddenly on close)
20 */
21
22export function useFirstFocusedRender(focused, open) {
23 const ref = useRef(false);
24 return ref.current || (focused || !!open) && (ref.current = true);
25}
\No newline at end of file