DEV Community

Wenchen "Neo" Li
Wenchen "Neo" Li

Posted on

React Hooks Released! (Finally 🎉)

After a lot of waiting...

We finally have React with Hooks to use!

I also created a custom hook to use scroll position last month:

GitHub logo neo / react-use-scroll-position

A react hook to use scroll position


npm package

A react hook to use scroll position.


In a React functional component:

import React from 'react';
// Usually you would just need to import one of the following
import { useScrollPosition, useScrollXPosition, useScrollYPosition } from 'react-use-scroll-position';
function Example() {
  const { x, y } = useScrollPosition();
  const scrollX = useScrollXPosition();
  const scrollY = useScrollYPosition();
  return (
        {x} should equal to {scrollX}
        {y} should equal to {scrollY}

In a custom React hook

import { useScrollPosition } from 'react-use-scroll-position';
function useYourImagination() {
  const { x, y } = useScrollPosition();
  return getSomethingAwesomeWith(x, y

Discussion (3)

dance2die profile image
Sung M. Kim • Edited on

I can find myself using react-use-scroll-position 👍

And I found that devDependencies are still not up to date.

I believe react should be updated to v16.8.0 (which I did for my small hook library 😉) while TypeScript is now 3.3.x as well as the type definition .

li profile image
Wenchen "Neo" Li Author

Very good point! Thank you v much for pointing it out!

dance2die profile image
Sung M. Kim

You're welcome. I had a similar problem this morning not updating dev deps :)