Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

ChildrenHash

YashTotale edited this page Dec 4, 2020 · 7 revisions

ChildrenHash

Summary

Scrolls to corresponding child element when one of the hashes is present in the url

Demo

View Children Hash Demo

Props

hashes

behavior

position

requiredPathname

scrollFunc

Example

import React from "react";
import { BrowserRouter } from "react-router-dom"; //Can use HashRouter or MemoryRouter as well
import { ChildrenHash } from "react-hash-scroll";

const App = () => {
  return (
    <BrowserRouter>
      <ChildrenHash
        hashes={[
          "#div",
          { hash: "#heading", behavior: "smooth" },
          { hash: "#paragraph", position: "end" },
        ]}
        requiredPathname={["/login", "/signup"]}
      >
        <div ref={ref1}>Element #1</div>
        <h4 ref={ref2}>Element #2</h4>
        <p ref={ref3}>Element #3</p>
      </ChildrenHash>
    </BrowserRouter>
  );
};
Clone this wiki locally