Is there any chance to make this code DRY?
let allPosts = this.state.posts.map((item, i, arr) => {
if (i === arr.length - 1) {
return <Post
key={item._id}
post={item}
nickname={this.props.nickname}
ref={this.lastPostRef}
/>
}
return <Post
key={item._id}
post={item}
nickname={this.props.nickname}
/>
});
The perfect solution would be
...
nickname={this.props.nickname}
if (i === arr.length - 1) {
ref={this.lastPostRef}
} ...
but it doesn't work in React.