Udemy-React-Course
  • Introduction
  • CodeSandbox で作る開発環境
    • CodeSandbox を使う利点
    • GitHub との連携
    • CodeSandbox の構造
  • 初めての React App
    • 最小限の React アプリケーションの実装
    • JSX と React Element
    • ES2015 のアロー関数について
    • React でアロー関数を使用する
    • 初めての React Component
    • ES2015 の import / export
    • export default
    • 2章の復習
  • State を持ったコンポーネント
    • State とは何か
    • ES2015 の class
    • React Class Component の書き方
    • click された時に setState で state を変更する
    • H20 Component 1
    • H20 Component 2
    • H20 Component 3
    • H20 Component 4
    • map と filter
    • map と filter の実践
  • 実践:TodoApp の作成
    • TodoApp の作成
  • 非同期処理, Promise, Ajax
    • HTTP プロトコルと AJAX
    • 非同期処理と Promise
    • JSON を取得し、その内容をレンダリングする React App の作成
  • 実践:API を叩く App
    • Giphy API を使用して、GIF画像検索する React App の作成
  • Redux の導入
    • Redux の概要
    • createStore で store を作る
    • Provider と Connect / store を React で使用する
    • Redux の全体像の確認
    • Presentational Component と Container Component
    • Action Creator
    • Combine Reducer
  • Redux-thunk を用いた非同期処理
    • Redux-thunk で非同期にアクションを発行する
    • Promise を Redux-thunk 上で活用する
  • React + Redux + Redux を用いた Giphy App
    • store を作る
    • Component に store を connect する
    • Search コンポーネントの作成
    • GiphyAPI を叩くメソッドの作成と Redux-thunk を使った非同期処理
    • 改善
  • 補足資料
    • App = ({name}) => name 型のシンタックス / Destructuring assignment
    • Class Component と Functional Component の使いわけ
  • 参考資料と謝辞
Powered by GitBook
On this page
  • filter
  • map
  1. State を持ったコンポーネント

map と filter の実践

Previousmap と filterNext実践:TodoApp の作成

Last updated 7 years ago

filter

import React from "react";
import { render } from "react-dom";

const todos = [
  { id: 1, title: "title1" },
  { id: 2, title: "title2" },
  { id: 3, title: "title3" },
  { id: 4, title: "title4" }
];

const deleteTargetId = 3;

// filter を使って
// deleteTargetId 以外のものだけを採用する

const deletedArray = todos.filter(todo => todo.id !== deleteTargetId);

console.log(deletedArray);

map

import React from "react";
import { render } from "react-dom";

const todos = [
  { id: 1, title: "title1" },
  { id: 2, title: "title2" },
  { id: 3, title: "title3" },
  { id: 4, title: "title4" }
];

const deleteTargetId = 3;

const deletedArray = todos.filter(todo => todo.id !== deleteTargetId);

console.log(deletedArray);

// 新しい React Component である Todos を 
// map を使って作成する

const Todos = ({ todos }) => {
  // 一旦 List へ、受け取った配列(todos)を元に
  // li 要素を複数保持した、新しい配列を入れる
  const list = todos.map(todo => {
    return (
      <li>
        {todo.id} {todo.title}
      </li>
    );
  });

  // 先ほど作った list を使用する
  // この部分が実際にレンダリングされる内容
  return <ul>{list}</ul>;
};

render(<Todos todos={todos} />, document.getElementById("root"));

https://codesandbox.io/s/jl8v3n7r6y
https://codesandbox.io/s/2wr8mq3nqy