Sniberb
Sniberb3y ago

⛄ Snowberb ⛄ – 07-50 Jul 5

How can I accomplish the same but in a cleaner way?
export const getStaticProps: GetStaticProps = async () => {
const { bettingBonuses, casinoBonuses } = getBonuses
const { getAccounts, getTransactions } = getAccountInfo
let savedBonuses: IBonus[] = []
let savedCasinoBonuses: IBonus[] = []
let savedBets: Bet[] = []
let savedAccounts: Account[] = []
let savedTransactions: Transaction[] = []

try {
const promises = await Promise.allSettled([
bettingBonuses(),
casinoBonuses(),
getBets(),
getAccounts(),
getTransactions(),
])
const filteredPromises = promises.map((promise) =>
promise.status === 'fulfilled' ? promise.value : []
)

savedBonuses = filteredPromises[0] as IBonus[]
savedCasinoBonuses = filteredPromises[1] as IBonus[]
savedBets = filteredPromises[2] as Bet[]
savedAccounts = filteredPromises[3] as Account[]
savedTransactions = filteredPromises[4] as Transaction[]
} catch (err) {}

return {
props: {
savedBonuses,
savedCasinoBonuses,
savedBets,
savedAccounts,
savedTransactions,
},
}
}
export const getStaticProps: GetStaticProps = async () => {
const { bettingBonuses, casinoBonuses } = getBonuses
const { getAccounts, getTransactions } = getAccountInfo
let savedBonuses: IBonus[] = []
let savedCasinoBonuses: IBonus[] = []
let savedBets: Bet[] = []
let savedAccounts: Account[] = []
let savedTransactions: Transaction[] = []

try {
const promises = await Promise.allSettled([
bettingBonuses(),
casinoBonuses(),
getBets(),
getAccounts(),
getTransactions(),
])
const filteredPromises = promises.map((promise) =>
promise.status === 'fulfilled' ? promise.value : []
)

savedBonuses = filteredPromises[0] as IBonus[]
savedCasinoBonuses = filteredPromises[1] as IBonus[]
savedBets = filteredPromises[2] as Bet[]
savedAccounts = filteredPromises[3] as Account[]
savedTransactions = filteredPromises[4] as Transaction[]
} catch (err) {}

return {
props: {
savedBonuses,
savedCasinoBonuses,
savedBets,
savedAccounts,
savedTransactions,
},
}
}
1 Reply
reactibot
reactibot3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/993785907645792346 Question not getting answered? Maybe it's hard to answer, or maybe you asked at a slow time. Check out these resources for help asking a good question: https://stackoverflow.com/help/how-to-ask http://wp.me/p2oIwo-26

Did you find this page helpful?