React Hooks Released! (Finally 🎉)

github logo ・1 min read

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:

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);

Implementation details

The scroll event handler is throttled by requestAnimationFrame

twitter logo DISCUSS (3)
markdown guide

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 .


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


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

Classic DEV Post from Dec 31 '18

Dealing with copyright infringement and plagiarism

This is a story all about how my life got twisted upside down, and I'd like to ...

Wenchen Li (Neo) profile image
Making fancy and novel web stuff 🤯