wellyshen / react-cool-inview

😎 🖥️ React hook to monitor an element enters or leaves the viewport (or another element).

Home Page:https://react-cool-inview.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typescript typing wrong for observe

cameronbraid opened this issue · comments

You need to change observe to accept an optional element

I get an error when using useInView and useDimensions when trying to compose the observe callback :

  const { observe:observeInView, inView } = useInView({...})

  const { observe:observeDimension, currentBreakpoint } = useDimensions({...})

  let combinedObserve = useCallback(el=>{
    observeInView(el);
    observeDimension(el);
  }, [observeInView, observeDimension])

ts error is Expected 0 arguments, but got 1.ts(2554)

This is because observe is defined as :

    observe: () => void;

it needs to look something like

    observe: (element?: HTMLElement) => void

@cameronbraid The type is observer: (element?: T) => void (https://github.com/wellyshen/react-cool-inview/blob/master/src/react-cool-inview.d.ts#L14) already in the latest version. Please check your version.

I am on 2.0.2 For some reason my npm wont upgrade to 2.0.3 but that's my problem not yours :)

Thanks mate.