NA +91-8727899942 thecoderjob@gmail.com

CHAPTER - 47

useLocation Hooks

It is important because, it gather all information when we move one route to another.

Here's is the Code !!

import React from "react";
import { useLocation } from "react-router-dom";

function MyComponent() {
  // Access the current location using the useLocation hook
  const location = useLocation();

  return (
    <div>
      <h2>Current Pathname:</h2>
      <p>{location.pathname}</p>

      <h2>Current Search:</h2>
      <p>{location.search}</p>

      <h2>Current Hash:</h2>
      <p>{location.hash}</p>

      <h2>Previous State:</h2>
      <p>{location.state}</p>
    </div>
  );
}

export default MyComponent;

Chapter 48

Protected Route

Previous chapter

Get In Touch

NA

thecoderjob@gmail.com

+91-8727899942

Popular Links

© www.thecoderjob.com. All Rights Reserved.               Designed by HTML Codex