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

Popular posts from this blog

javascript - Training Neural Network to play flappy bird with genetic algorithm - Why can't it learn? -

service - Android MediaPlayer calls onCompletion before it already finished -

javascript - Create a stacked percentage column -