4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Javascript(react) 多次元配列をテーブルに挿入するfunction component

Last updated at Posted at 2020-11-25

オライリージャパンreatビギナーズガイドの練習課題『高機能excel作成を作ろう』にて
多次元配列の処理をclass componentで書かれていた。
function componentの理解のため、function componentに書き換えていく。

参考書籍:reactビギナーズガイド
サンプルコード:https://github.com/stoyan/reactbook
該当フォルダ・ファイル:chapters/03.04.table-sortby.html

FireShot Capture 003 - React App - localhost.png
配列の要素は適当に違う値を使用します。

#土日がない?休みなんか必要ないですよね?笑

Table.jsx

function Table() {

  const heads = ["", "", "", "", ""]
  const heads1 = heads.map((head) =>
    <th>{head}</th>
  )

  const data = [
           [1, 2, 3, 4, 5], 
           [6, 7, 8, 9, 10,], 
           [11, 12, 13, 14, 15], 
           [16, 17, 18, 19, 20,], 
           [21, 22, 23, 24, 25], 
           [26, 27, 28, 29, 30,]
               ]



  return (
    <div>
      <table border='1' cellSpacing='0'>
        <tr>{heads1}</tr>
        {data.map(row1 =>
          <tr>
            {row1.map(row2 =>
              <td>{row2}</td>
            )}
          </tr>
        )}
      </table>
    </div>
  );
}

export default Table;

(随時更新予定)

#react
#ファンクションコンポーネント
#Table
#多次元配列
#二次元配列
#map関数

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?