App:
const App = (props) => {
return (
);
};
Account:
class Account extends Component {
constructor(props) {
super(props);
this.state = {
id: this.props.match.params.id,
name: '',
email: '',
password: '',
link: ''
}
}
componentDidMount() {
console.log(this.state.id)
// eslint-disable-next-line
if (this.state.id === -1) {
return
}
ApiService.fetchAccountById(this.state.id)
.then(response => this.setState({
item: {
name: response.data.name,
email: response.data.email,
password: response.data.password,
link: response.data.link
}
}))
}
render() {
let acc = this.state.item;
return (
Account
{acc.id}
{acc.name}
{acc.email}
{acc.password}
{acc.link}
)
}
ApiService:
const ACCOUNT_API_BASE_URL = 'http://localhost:8080/api/accounts';
class ApiService {
fetchAccounts() {
return axios.get(ACCOUNT_API_BASE_URL);
}
fetchAccountById(id) {
return axios.get(`${ACCOUNT_API_BASE_URL}/${id}`);
}
addAccount(acc) {
return axios.post(ACCOUNT_API_BASE_URL + '/create', acc);
}
}