Skip to content

Instantly share code, notes, and snippets.

@irridescentrambler
Created June 30, 2022 10:38
Show Gist options
  • Save irridescentrambler/a3842650df4610a751a8490b3cccb4e3 to your computer and use it in GitHub Desktop.
Save irridescentrambler/a3842650df4610a751a8490b3cccb4e3 to your computer and use it in GitHub Desktop.
import { React } from 'react';
import Axios from 'axios';
class Demo extends React.Component{
initialize(){
this.state = {
userInput: nil,
employees: [],
status: nil
}
}
takeInput = function(event){
this.setState({
userInput: event.target.value
})
}
callApi = function(){
// response = { employees: [{ name: "ABC", phoneNumber: "XYZ" }, {}, {}] }
Axios.get("/employees").then(function(response){
this.setState({
status: true,
employees: response.employees
})
}).catch(function(response){
this.setState({
status: false
})
})
}
componentDidMount(){
this.callApi();
}
render(){
return(
<div>
<input onChange={ this.takeInput }></input>
<p>{ this.state.userInput }</p>
<p>
{
this.state.status && this.state.employees
}
</p>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment