Created
June 30, 2022 10:38
-
-
Save irridescentrambler/a3842650df4610a751a8490b3cccb4e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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