-
-
Save AHaydar/c0dcf965ad579b182ec32021ce5f7ea6 to your computer and use it in GitHub Desktop.
This file contains 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, { useState } from 'react'; | |
const CompanyDetails = ({ companyId, companyName }) => { | |
const url = | |
'https://nfc079xjo3.execute-api.us-east-1.amazonaws.com/Prod/companies'; | |
const [returnedRevenue, setReturnedRevenue] = useState([]); | |
const handleClick = () => { | |
fetch(`${url}/?companyId=${companyId.split('#')[1]}`) | |
.then((response) => response.json()) | |
.then((data) => { | |
setReturnedRevenue(data); | |
}); | |
}; | |
return ( | |
<li> | |
{companyName} <button onClick={handleClick}>Show revenue</button> | |
<div> | |
{returnedRevenue.length ? returnedRevenue[0].Details.revenue : ''} | |
</div> | |
</li> | |
); | |
}; | |
export default CompanyDetails; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment