The monolithic component we're going to implement is a feature that lists articles. It's just for illustrative purposes, so we don't want to go overboard on the size of the component. It'll be simple, yet monolithic. The user can add new items to the list, toggle the summary of items in the list, and remove items from the list. Here is the render method of the component:
render() {
const { articles, title, summary } = this.data.toJS();
return (
<section>
<header>
<h1>Articles</h1>
<input
placeholder="Title"
value={title}
onChange={this.onChangeTitle}
/>
<input
placeholder="Summary"
value={summary}
onChange={this.onChangeSummary}
/>
<button onClick={this.onClickAdd}>Add</button>
</header>
<article>
<ul>
{articles.map(i => (
<li key={i.id}>
<a
href={`#${i.id}`}
title="Toggle Summary"
onClick={this.onClickToggle.bind(null, i.id)}
>
{i.title}
</a>
<a
href={`#${i.id}`}
title="Remove"
onClick={this.onClickRemove.bind(null, i.id)}
>
✗
</a>
<p style={{ display: i.display }}>{i.summary}</p>
</li>
))}
</ul>
</article>
</section>
);
}
Definitely more JSX than is necessary in one place. You'll improve on this in the following section, but for now, let's implement the initial state for this component.
I strongly encourage you to download the companion code for this book from https://github.com/PacktPublishing/React-and-React-Native-Second-Edition. I can break apart the component code so that I can explain it on these pages. However, it's an easier learning experience if you can see the code modules in their entirety, in addition to running them.