Protip - return from exceptional conditions early

During a recent code interview, I noticed a React component with a render method written in the following (abbreviated) form,

1
2
3
4
5
6
7
8
9
10
11
12
render() {
return this.state.items.length > 0 ? (

prop1={},
prop2={},
propN={},
...
/>
) : (
''
);
}

where ComponentWithLotsOfProps had at least a dozen props, some of which were not simple primitive values.

While there is nothing technically wrong with this render method, it could be better. It suffers from a few...

class="line">}whereclass="code"><td
 •  0 comments  •  flag
Share on Twitter
Published on November 07, 2019 09:24
No comments have been added yet.


Nicholas Cloud's Blog

Nicholas Cloud
Nicholas Cloud isn't a Goodreads Author (yet), but they do have a blog, so here are some recent posts imported from their feed.
Follow Nicholas Cloud's blog with rss.