No.
2022-01-07
  • Jan
  • Feb
  • Mar
  • Apr
  • May
  • Jun
  • Jul
  • Aug
  • Sep
  • Oct
  • Nov
  • Dec
  • Sun
  • Mon
  • Tue
  • Wed
  • Thu
  • Fri
  • Sat
  • 27
  • 28
  • 29
  • 30
  • 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
  • 31
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

やったこと

今日もfrontの課題を進めた

その前にReactの記事で興味深いものがあった
それがuseMemoのコストを心配する前に余計なdivを減らせ!である

useMemoのコストを心配する前に余計なdivを減らせ!

React では、useMemoやReact.memoなどが最適化の手段である
これらは、最適化をするためのものなので、むやみやたらに使うと逆にパフォーマンスを下げかねない
しかし、あるコンポーネントが一つ余計なuseMemoを持っているよりも、一つ余計な<div>をレンダリングする方が、
パフォーマンス(レンダリングにかかる時間)をより悪化させるという事実がある

したがって、useMemoなどを減らすことに執心する場合は、それと同等以上の熱量で余計な要素を減らすことに執心するのが良い
スクリーンショット 2022-01-07 10 17 34

SVGタグ

svg 要素は、新しい座標系とビューポートを定義するコンテナ
SVG ドキュメントの最も外側の要素として使用されますが、SVG または HTML ドキュメントの中に SVG フラグメントを埋め込むためにも使用できる

svgとは

SVG は Scalable Vector Graphics の略で、二次元グラフィックスを XML で記述するための言語(テキストファイル)であり、ベクター形式の画像フォーマット

marginの複数指定

  • 1つ: 四方向同じ
  • 2つ: 上下、左右
  • 3つ: 上、左右、下
  • 4つ: 上、右、下、左

Molecules/card

なんであれで三角形ができてるの?

BORDERだけで三角形ができる仕組み

borderの特性を知る

.triangle{
  width: 100px;
  height: 100px;
  border-top: 10px solid #F0897F;
}

上のCSSの場合、結果は スクリーンショット 2022-01-07 13 08 14
このようになる

そして、右にborderを追加すると

.triangle{
  width: 100px;
  height: 100px;
  border-top: 10px solid #F0897F;
  border-right: 10px solid #f6da69;
}

スクリーンショット 2022-01-07 13 08 56

結果は上のようになる
ここで注目するのは、border同士の接地面が斜めになっていること
スクリーンショット 2022-01-07 13 11 18
あとはどこを透明色にするか次第で三角形の向きが決まる

hackason

JSXでDate型を表示したい

結論: Date型はobjectなので表示できない
それをtoString()で変換することで表示できる

また、momentのパッケージをinstallしたところ、めちゃくちゃ簡単にDateをformat指定できた
参考

useContext

React TSでuseContext, createContextを使うときの型指定がややこしかった
useStateの関数を指定する時の型

setCount: Dispatch<SetStateAction<number>>

では

const CountContext = React.createContext()

と初期値の指定は必須ではなかったが
TypeScriptでは初期値を必ず設定してあげる必要がある

参考資料 useContextとuseStateを組み合わせ

contextを関数と値で分割したら、こんなに長くなったが果たして正しいのか??
一つにまとめなかった理由: 何か一つのstateが変更されたらほか全てのコンポーネントが再レンダリングされてしまうから

  export const ApplyUseLanguageContext = createContext<string | undefined>(undefined);
  export const SetApplyUseLanguageContext = createContext(
    {} as Dispatch<SetStateAction<string | undefined>>
  );
  export const ApplyUsernameContext = createContext<string | undefined>(undefined);
  export const SetApplyUsernameContext = createContext(
    {} as Dispatch<SetStateAction<string | undefined>>
  );
  export const ApplyKeywordContext = createContext<string | undefined>(undefined);
  export const SetApplyKeywordContext = createContext(
    {} as Dispatch<SetStateAction<string | undefined>>
  );
  export const ApplyStartDateContext = createContext<Date | undefined>(undefined);
  export const SetApplyStartDateContext = createContext(
    {} as Dispatch<SetStateAction<Date | undefined>>
  );
  export const ApplyEndDateContext = createContext<Date | undefined>(undefined);
  export const SetApplyEndDateContext = createContext(
    {} as Dispatch<SetStateAction<Date | undefined>>
  );
export const ApplyPostProvider = (props: { children: ReactNode }) => {
  const { children } = props;
  const [applyUseLanguage, setApplyUseLanguage] =
    useState<string | undefined>("");
  const [applyUsername, setApplyUsername] = useState<string | undefined>("");
  const [applyKeyword, setApplyKeyword] = useState<string | undefined>("");
  const [applyStartDate, setApplyStartDate] =
    useState<Date | undefined>(undefined);
  const [applyEndDate, setApplyEndDate] = useState<Date | undefined>(undefined);
  return (
  <>
    <ApplyUseLanguageContext.Provider value={applyUseLanguage} >
      <SetApplyUseLanguageContext.Provider value={setApplyUseLanguage}>
        <ApplyUsernameContext.Provider value={applyUsername}>
          <SetApplyUsernameContext.Provider value={setApplyUsername}>
            <ApplyKeywordContext.Provider value={applyKeyword}>
              <SetApplyKeywordContext.Provider value={setApplyKeyword}>
                <ApplyStartDateContext.Provider value={applyStartDate}>
                  <SetApplyStartDateContext.Provider value={setApplyStartDate}>
                    <ApplyEndDateContext.Provider value={applyEndDate}>
                      <SetApplyEndDateContext.Provider value={setApplyEndDate}>
                        {children}
                      </SetApplyEndDateContext.Provider>
                    </ApplyEndDateContext.Provider>
                  </SetApplyStartDateContext.Provider>
                </ApplyStartDateContext.Provider>
              </SetApplyKeywordContext.Provider>
            </ApplyKeywordContext.Provider>
          </SetApplyUsernameContext.Provider>
        </ApplyUsernameContext.Provider>
      </SetApplyUseLanguageContext.Provider>
    </ApplyUseLanguageContext.Provider>
  </>
  );
};