add early returns to renderPollStats()

This commit is contained in:
KDSBrowne 2018-10-31 13:28:32 +00:00
parent a8ef2cb8b5
commit 0e26d2a6c1

View File

@ -98,30 +98,30 @@ class LiveResult extends Component {
const pollStats = []; const pollStats = [];
if (currentPoll) { if (!currentPoll) return;
const {
answers,
numRespondents,
} = currentPoll;
if (answers) { const {
answers.map((obj) => { answers,
const pct = Math.round(obj.numVotes / numRespondents * 100); numRespondents,
} = currentPoll;
return pollStats.push(<div className={styles.main} key={_.uniqueId('stats-')}> if (!answers) return;
<div className={styles.left}>
{obj.key} answers.map((obj) => {
</div> const pct = Math.round(obj.numVotes / numRespondents * 100);
<div className={styles.center}>
{obj.numVotes} return pollStats.push(<div className={styles.main} key={_.uniqueId('stats-')}>
</div> <div className={styles.left}>
<div className={styles.right}> {obj.key}
{`${isNaN(pct) ? 0 : pct}%`} </div>
</div> <div className={styles.center}>
</div>); {obj.numVotes}
}); </div>
} <div className={styles.right}>
} {`${isNaN(pct) ? 0 : pct}%`}
</div>
</div>);
});
return pollStats; return pollStats;
} }