import React, {Component} from 'react'; class App extends Component { constructor(props){ super(props) this.onHandleUsers = this.onHandleUsers.bind(this) this.tekstas = "a"; this.state = { isLoaded: false, users: [] } } handleUserChange = (e) => { const {value} = e.target this.onHandleCurrentUsers(value) this.tekstas = this.onHandleCurrentUsers(value) } onHandleUsers() { fetch("http://localhost:3000/api/users") .then(res => res.json()) .then(result => { this.setState({ isLoaded: true, users: result }) }) .catch(e => console.log(e)) } onHandleCurrentUsers(userId) { const data = {userId: userId} fetch("http://localhost:3000/api/user", { method: 'POST', headers: { "Content-Type": "application/json"}, body: JSON.stringify(data) }) .then(res => res.json()) .then(result => { this.setState({ isLoaded: false, currentUser: result }) }) .catch(e => console.log(e)) } render() { const {currentUser} = this.state return (
{ currentUser &&
{currentUser.name} {currentUser.surname}
}
{this.tekstas}
) } } export default App