Basic auction optimization of code and null checks#226
Basic auction optimization of code and null checks#226vishwasrvalke wants to merge 3 commits intoRealDevSquad:developfrom
Conversation
correaswebert
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
You could use the new syntax here!
JSON.parse(response.auctions ?? 0)
It mostly won't need the fallback || 0 as well 😄
| }; | ||
|
|
||
| useEffect(() => { | ||
| (async () => { |
There was a problem hiding this comment.
Please create named functions!
Reading and understanding stack traces would be far easier and better 😄
async function funcname = () => {}
funcname()
There was a problem hiding this comment.
It's an IIFE ,please recheck the implementation,thanks
| await fetchAndSetAuctions(); | ||
| await getUserWallet(); | ||
| await fetchSelfDetails() | ||
| .then((res) => { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Use the auctionsData?.length syntax, it's simpler 😄
| > | ||
| const auctionHandler = | ||
| auctionsData && auctionsData.length | ||
| ? auctionsData.map(({ id, seller, quantity, highest_bid, bidders }) => { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Please use the inline && operator to avoid the null condition 😄
|
Sure will do thanks. |
|
@vishwasrvalke Would you like to fix this PR so that we can merge it? |
ADDED NULL CHECKS TO PREVENT PAGE FROM CRASHING ON API FAIL ,
Optimisation of code and leakages with async calls and hooks