Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created August 9, 2021 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save percybolmer/5dada9bab9af38b88dd1354d674465e9 to your computer and use it in GitHub Desktop.
Save percybolmer/5dada9bab9af38b88dd1354d674465e9 to your computer and use it in GitHub Desktop.
import { useParams, useLocation } from "react-router-dom";
import React from 'react';
const Profile = () => {
// Use the useParams hook to get the username from the URL
// username has to be applied as a named parameter in the route
let { username } = useParams();
// useLocation hook is used to grab the state from the input to object
// You can grab each field in the object by using the same name as the variable name
let { pathname } = useLocation();
let { state } = useLocation();
return (
<div>
<h1>{username} Profile</h1>
<p> Registered on:{state.registrationdate} </p>
<p> Visiting: {pathname}</p>
</div>
)
}
export default Profile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment