Crypto Prices Flashcards
Property to add to table header?
scope=”col”
What does scope=”col” do?
Added for accessibility used for header <th> elements to indicate that all cells below this column relate to it.
What is the outline of the table?
<table>
<caption>Crypto Prices</caption>
<thead>
<tr>
<th>Coin</th>
<th>Price</th>
<th>Market Cap</th>
</tr>
</thead>
<tbody>
<tr>
<th>Bitcoin</th>
<td>$29,970.48</td>
<td>$57,108,740,782</td>
</tr>
</tbody>
</table>
Explain different functionality with how errors are handled with and without try/catch
With a try/catch, the error will not cause the script to stop executing.
If no catch, the error will be logged to the console by default and script will stop executing.
Do you need catch with a try?
No, but if you don’t have catch, you will need a finally block.
What property do you need to pass jsx elements in a loop?
the “key” prop, with a unique value.
What value should you use to disable the next and back buttons?
You should use hasPrev and hasNext from the api. If hasPrev is not available, the use page === 0. If hasNext is not available then use the page and limit to calculate if you are on the last page.
What state is needed for CryptoPrices?
const [page, setPage] = useState(0);
const [cryptoData, setCryptoData] = useState({});
What does the useEffect look like?
useEffect(() => {
const fetchCrypto = async () => {
try {
const res = await fetch(${api}?page=${page}
);
const json = await res.json();
setCryptoData(json); catch (e) { // Display error to the user console.log('Error', e); } }
fetchCrypto();
}, [page]);