Skip to content

Conversation

@vishwasrvalke
Copy link

ADDED NULL CHECKS TO PREVENT PAGE FROM CRASHING ON API FAIL ,
Optimisation of code and leakages with async calls and hooks

Copy link

@correaswebert correaswebert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great changes done 👍🏾 🥳
Recommended some minor tweaks which will improve code readability!

setAuctionsData(json.auctions);
if (!response) return null;
setAuctionsData(
JSON.parse(response && response.auctions ? response.auctions : 0) || 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use the new syntax here!
JSON.parse(response.auctions ?? 0)
It mostly won't need the fallback || 0 as well 😄

};

useEffect(() => {
(async () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create named functions!
Reading and understanding stack traces would be far easier and better 😄

async function funcname = () => {}
funcname()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an IIFE ,please recheck the implementation,thanks

await fetchAndSetAuctions();
await getUserWallet();
await fetchSelfDetails()
.then((res) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't mix the .then().catch() syntax with async-await if not needed.
You can wrap the block in a try-catch as any of the above requests could also fail 😓

title={bidder}
>
const auctionHandler =
auctionsData && auctionsData.length

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the auctionsData?.length syntax, it's simpler 😄

>
const auctionHandler =
auctionsData && auctionsData.length
? auctionsData.map(({ id, seller, quantity, highest_bid, bidders }) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a sub-component which you can then use in the ternary operator...
Easier to read and understand the fallback, which in this case we have to scroll a lot to find 😅

</div>
);
})
: null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the inline && operator to avoid the null condition 😄

@vishwasrvalke
Copy link
Author

Sure will do thanks.

@MehulKChaudhari
Copy link
Contributor

@vishwasrvalke Would you like to fix this PR so that we can merge it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants