LeetCode-OpenSource/rxjs-hooks

Question about useEventCallback.

hooksw opened this issue · 1 comments

I tryed the following code :

const [onMouseDown] = useEventCallback<React.MouseEvent<HTMElement>>((event$) => event$.pipe(
        switchMap((event) => fromEvent(window, "mousemove").pipe(
            throttleTime(100),
            tap(() => {
                if (leftWidth < left_minWidth || getRightWidth(leftWidth) < right_minWidth) return;
                setLW(event.currentTarget.getBoundingClientRect().width)
            }),
            takeUntil(fromEvent(window, 'mouseup'))
        ))
    ))

and got such an error:

Type 'Observable<Event>' is not assignable to type 'Observable<void>'.   Type 'Event' is not assignable to type 'void'.

When I ignore it and run , I get other errors in the browser:

react-dom.development.js:530 Warning: This synthetic event is reused for performance reasons. If you're seeing this, you're accessing the method currentTarget on a released/nullified synthetic event.

hostReportError.js:5 Uncaught TypeError: event.currentTarget.getBoundingClientRect is not a function

I feel confused, but....I can't find out the solution. 😥

The first question seems to be a type problem in your TS code, but I cannot figure it out from this code snippet.

The second problem is explained in its error message, your way to use React Synthetic event is wrong. Please refer to React official documents.