Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including react-hash-handler with all npm packages installed. Try it out:

require("react/package.json"); // react is a peer dependency. var reactHashHandler = require("react-hash-handler")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

react-hash-handler v0.1.7

React component that makes it easy to compose hashchange and hash click handling into your application or site.


npm version npm Coverage Status CircleCI Greenkeeper badge

React component that makes it easy to compose hashchange and hash click handling into your application or site.


Install via npm

npm install --save react-hash-handler

Install via Yarn

yarn add react-hash-handler

How to use

At its core, the HashHandler is a pretty straight-forward component that doesn’t do much beyond letting your site or app know when the hash changes, or when a hash link is clicked. Feel free to use it however you want via the callback props that are available on the component.


  • onChange:Func - Called when the browser hashchange event is fired.

  • onClick:Func - Called when a hash link (ex. <a href="#contact">Contact</a>) is clicked.


import React, { Component } from 'react';
import TargetScroller from 'react-target-scroller';
import HashHandler from 'react-hash-handler';

class ExampleComponent extends Compnonent {
  constructor(props) {

    this.state = {
      scrollTarget: null,

    this.onHashChange = this.onHashChange.bind(this);
    this.onHashClick = this.onHashClick.bind(this);

  onHashChange({hash}) {
      scrollTarget: `#${hash}`,

  onHashClick({hash}) {
      scrollTarget: `#${hash}`,

  render() {
    const {
    } = this.state;

    return (
      <div className="page-wrapper">
        <TargetScroller target={scrollTarget} />
            <li><a href="#overview">Overview</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>
        <section id="overview">
        <section id="about">
        <section id="contact">


MIT © Ryan Hefner

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free