Entries from 2019-03-16 to 1 day

setStateで配列更新するパターン

とにかく、元のstateにある配列を直接いじらないこと。 class Shelf extends Component { constructor(props) { super(props); this.state = { books: [{ id: 0, title: "Never Ending Story" }], controlId: 1, }; } addBook(title) { const { books, contr…

前のディレクトリに戻る

いっつも忘れる🐶 $ cd -

Functional Component & Class Component

Functional Component import React from 'react'; const Cheers = (props) => { return <div>Hello, {props.name}!!</div>; } Class Component ・stateを利用してコンポーネントの状態を記録できる ・ライフサイクルメソッドを利用できる import React from 'react'; c…

webpack is...

webpack = モジュールバンドラー CommonJSのモジュール方式で書かれたスクリプトをまとめて、JSファイルを出力する。 npmパッケージを使う上で、避けては通れないツール。 Loaderという仕組みにより、スクリプトをまとめる前に任意の処理(例: JSXのトランス…

zshでgit reset --soft HEAD^出来なくて焦った

キャレットは使えないんだと🕵🏻‍♂️ ~/w/s/t/src ❯❯❯ git reset --soft HEAD^ zsh: no matches found: HEAD^ ~/w/s/t/src ❯❯❯ git reset --soft HEAD\^ ~/w/s/t/src ❯❯❯ git s M index.js参考 qiita.com

Avoiding Mutation

JSで元のオブジェクトに変更を加えずに処理したい時配列 // 元の配列に変更を加えず、一段階の深さのコピーを返す var shallowCopy = fruits.slice(); // 連結 var array1 = ['a', 'b', 'c']; var array2 = ['d', 'e', 'f']; console.log(array1.concat(arra…