javascript - In React/ES6, is there a more concise way to write a ternary that references an attribute? -
in code right now, have bunch of code this: startervalue={ elementtoedit ? elementtoedit.size : null }
i can't elementtoedit.size || null or because of elementtoedit isn't defined, can't attribute.
is there more concise way write or should deal? thanks
assuming elementtoedit null when isn't present, can do
startervalue={ elementtoedit && elementtoedit.size } if undefined or other falsy value, value passed through instead, that's fine in usecase.
Comments
Post a Comment