Last active
August 18, 2020 13:57
-
-
Save skflowne/484f277853adb184f5950779605fbe2b 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 { selector, selectorFamily } from "recoil" | |
export const API_DATE_FORMAT = "yyyy-MM-dd" | |
export const countriesQuery = selector({ | |
key: "countries", | |
get: async () => { | |
try { | |
const res = await fetch("https://covid19-api.org/api/countries") | |
const countries = await res.json() | |
return countries.reduce((dict, country) => { | |
dict[country.alpha2] = country | |
return dict | |
}, {}) | |
} catch (e) { | |
console.error("ERROR GET /countries", e) | |
} | |
}, | |
}) | |
export const statusByDateQuery = selectorFamily({ | |
key: "status-by-date", | |
get: (formattedDate) => async ({ get }) => { | |
try { | |
const res = await fetch(`https://covid19-api.org/api/status?date=${formattedDate}`) | |
const status = await res.json() | |
return status | |
} catch (e) { | |
console.error("ERROR GET /statusByDate", e) | |
} | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment