I'm using a React functional component. I want to store the data received from an API to a variable so that I can use it in the rest of the code.
const Component = (props) =>{
let variable = {};
Agent.API.get(props.id)
.then((response)=>{
variable = response.data })
return(
<div><p>{variable.name}</p></div>
)
}
export default Component;
This is something I want to achieve. How do I go about?