Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, {Component} from "react";
- import c from './Account.module.css'
- import ApiService from "../../../ApiService";
- class Account extends Component {
- accountItem = {
- id: '',
- name: '',
- email: '',
- password: '',
- link: ''
- };
- constructor(props) {
- super(props);
- this.state = {
- item: this.accountItem
- };
- this.reloadAccount = this.reloadAccount.bind(this);
- }
- componentDidMount() {
- this.reloadAccount(this.id);
- }
- reloadAccount(id) {
- ApiService.fetchAccountById(id)
- .then((res) => {
- let account = res.data;
- this.setState({
- id: account.id,
- name: account.name,
- email: account.email,
- password: account.password,
- link: account.link
- })
- })
- }
- render() {
- const {item} = this.state;
- return (
- <div>
- <div className={c.account}>
- <ul>
- <li>Id: {item.id}</li>
- <li>Name: {item.name}</li>
- <li>Email: {item.email}</li>
- <li>Password: {item.password}</li>
- <li>Link: {item.link}</li>
- </ul>
- </div>
- </div>
- )
- }
- }
- export default Account;
- ApiService:
- const ACCOUNT_API_BASE_URL = 'http://localhost:8080/api/accounts';
- ...
- fetchAccountById(id) {
- return axios.get(ACCOUNT_API_BASE_URL + '/' + id);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement