Forked from percybolmer/React-SPA-Profile-UseLocation.js
Last active
September 16, 2021 14:19
-
-
Save imgVOID/7894fb023452f96ca30aed193bf64571 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useParams, useLocation } from "react-router-dom"; | |
import React from 'react'; | |
const Profile = () => { | |
// Используйте хук useParams для получения имени пользователя из URL. | |
// Имя пользователя должно быть применено в качестве именованного параметра в маршруте. | |
let { username } = useParams(); | |
// useLocation применяется для захвата состояния из входных данных в объект. | |
// Так можно захватить каждое поле в объекте, используя то же имя, что и имя переменной. | |
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