---
id: 5a24c314108439a4d4036148
title: Redux をメッセージアプリに接続する
challengeType: 6
forumTopicId: 301427
dashedName: connect-redux-to-the-messages-app
---
# --description--
`connect` を使用して React を Redux に接続する方法を理解したところで、メッセージを処理する React コンポーネントに応用してみましょう。
前回のレッスンで、Redux に接続したコンポーネントは `Presentational` という名前でしたが、これは勝手に付けたものではありません。 この用語は*全般的に*、Redux に直接接続していない React コンポーネントのことを指します。 これらのコンポーネントは、単に UI の表現部分 (プレゼンテーション) を担い、自身が受け取る props の関数としてその機能を実行します。 これに対して、コンテナーコンポーネントは Redux に接続します。 これらは通常、ストアにアクションをディスパッチする役割を担い、多くの場合、ストアの state を props として子コンポーネントに渡します。
# --instructions--
コードエディターには、ここまでこのセクションで記述したすべてのコードがあります。 一つだけ、React コンポーネントの名前が `Presentational` に変更されています。 `Container` という定数に保持する新しいコンポーネントを作成してください。このコンポーネントは、`connect` を使用して `Presentational` コンポーネントを Redux に接続します。 次に、`AppWrapper` の中で React Redux の `Provider` コンポーネントをレンダーしてください。 `Provider` に Redux の `store` を prop として渡し、`Container` を子としてレンダーしてください。 すべての設定が完了すると、再びメッセージアプリがページにレンダーされます。
# --hints--
`AppWrapper` をページにレンダーします。
```js
assert(
(function () {
const mockedComponent = Enzyme.mount(React.createElement(AppWrapper));
return mockedComponent.find('AppWrapper').length === 1;
})()
);
```
`Presentational` コンポーネントをページにレンダーします。
```js
assert(
(function () {
const mockedComponent = Enzyme.mount(React.createElement(AppWrapper));
return mockedComponent.find('Presentational').length === 1;
})()
);
```
`Presentational` コンポーネントで、`h2`、`input`、`button`、`ul` の各要素をレンダーします。
```js
assert(
(function () {
const mockedComponent = Enzyme.mount(React.createElement(AppWrapper));
const PresentationalComponent = mockedComponent.find('Presentational');
return (
PresentationalComponent.find('div').length === 1 &&
PresentationalComponent.find('h2').length === 1 &&
PresentationalComponent.find('button').length === 1 &&
PresentationalComponent.find('ul').length === 1
);
})()
);
```
`Presentational` コンポーネントで、Redux ストアから `messages` を prop として受け取ります。
```js
assert(
(function () {
const mockedComponent = Enzyme.mount(React.createElement(AppWrapper));
const PresentationalComponent = mockedComponent.find('Presentational');
const props = PresentationalComponent.props();
return Array.isArray(props.messages);
})()
);
```
`Presentational` コンポーネントで、`submitMessage` アクションクリエイターを prop として受け取ります。
```js
assert(
(function () {
const mockedComponent = Enzyme.mount(React.createElement(AppWrapper));
const PresentationalComponent = mockedComponent.find('Presentational');
const props = PresentationalComponent.props();
return typeof props.submitNewMessage === 'function';
})()
);
```
# --seed--
## --after-user-code--
```jsx
ReactDOM.render(