Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Account extends Component {
  2.     constructor(props) {
  3.         super(props);
  4.  
  5.         this.state = {
  6.             item: {
  7.                 id: props.match.params.id,
  8.                 name: '',
  9.                 email: '',
  10.                 password: '',
  11.                 link: ''
  12.             }
  13.         }
  14.  
  15.     }
  16.  
  17.     componentDidMount() {
  18.  
  19.         console.log(this.state.id)
  20.  
  21.         // eslint-disable-next-line
  22.         if (this.state.id === -1) {
  23.             return -1
  24.         }
  25.  
  26.         ApiService.fetchAccountById(this.state.id)
  27.             .then(response => this.setState({
  28.                 item: {
  29.                     name: response.data.name,
  30.                     email: response.data.email,
  31.                     password: response.data.password,
  32.                     link: response.data.link
  33.                 }
  34.             }))
  35.  
  36.     }
  37.  
  38.     render() {
  39.  
  40.         let acc = this.state.item;
  41.  
  42.         return (
  43.             <div>
  44.                 <h3>Account</h3>
  45.                 <div>{acc.id}</div>
  46.                 <div>{acc.name}</div>
  47.                 <div>{acc.email}</div>
  48.                 <div>{acc.password}</div>
  49.                 <div>{acc.link}</div>
  50.             </div>
  51.         )
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement