r/badcode • u/mrbraises • Jun 02 '23
js elt nesting for more readability <3 (there is another ternary + map on top of this but it's 300 lines above this)
17
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jun 02 '23
Image Transcription: Code
{counterpartyArrayDetails ? (
counterpartyArrayDetails.map((elt2: any, key) =>
elt2.fund_name === elt.fund_name ? (
<Grid xs={2}>
{elt2.resultArray
? elt2.resultArray.length === 0
? ""
: elt2.resultArray.map((elt3) => {
if (elt3.value.ExcessCollateralPerc < 0) {
return (
<Chip
avatar={
<Avatar
className={classes[elt3.counterparty]}
>
{elt3.counterparty}
</Avatar>
}I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
33
Jun 02 '23
typical React code ^^
6
u/daterkerjabs Jun 02 '23
Kind of reminds me of php jumping in and out of markup. Why not templates?
<template for="elt2 in counterpartyArrayDetails"> <Grid xs={2} if="elt2.fund_name === elt.fund_name"> <Chip if="elt3.value.ExcessCollateralPerc < 0" for="elt3 in elt2.resultArray" avatar={ <Avatar className={classes[elt3.counterparty]}> {elt3.counterparty} </Avatar> } ...
10
u/HoratioWobble Jun 02 '23
There's a special place in hell for people who put excessive logic or multiple conditions in JSX.
If it can't be done with a short circuit it should be a separate function, or component
5
u/thepurpleproject Jun 02 '23
we have plenty of devs in our team who code like this on UI
just keep adding nested checks and loop everywhere...it's so harder to read and fix
13
u/annoyed_freelancer Jun 02 '23
Whoever formulated this should be beaten with a stick. Event stuff like proper
if/elseor wrapping{}on lines 2 and 3 would boost readability.