I am working on a project and creating a website. the feature i am working on right now is the profile page for the user. i need to be able to have an edit button in the page that will allow the user to edit their name, username, email, and update password. The following is the code i have but i am unsure how to make everything work.
import React, {useEffect, useState} from "react";
import {useHistory} from "react-router-dom";
import axios from "axios";
const ProfilePage = () => {
const [user, setUser] = useState({});
const [sessionUrl,] = useState("/api/sessions/me");
const history = useHistory();
useEffect(() => {
(async () => {
try {
const response = await axios.get(sessionUrl);
setUser(response.data);
} catch (err) {
history.push({
pathname: "/account/login"
});
}
})();
}, []);
return (
<div>
<div>Name: {user.displayName}</div>
<div>Username: {user.username}</div>
<div>Email: {user.email}</div>
</div>
);
}
export default ProfilePage;