Refactoring the Collection component
Next, let’s refactor our Collection
component. Replace the existing Collection
component with the following:
import React, { Component } from ‘react’; import ReactDOMServer from ‘react-dom/server’; import CollectionControls from ‘./CollectionControls’; import TweetList from ‘./TweetList’; import Header from ‘./Header’; import CollectionUtils from ‘../utils/CollectionUtils’; import CollectionStore from ‘../stores/CollectionStore’; class Collection extends Component { state = { collectionTweets: CollectionStore.getCollectionTweets() } componentDidMount() { CollectionStore.addChangeListener(this.onCollectionChange); } componentWillUnmount() { CollectionStore.removeChangeListener(this.onCollectionChange); } onCollectionChange = () => { this.setState({ collectionTweets: CollectionStore.getCollectionTweets() ...