Reduxの導入

Next + TypeScript環境にReduxを導入する
一部のstoreはlocal storageにも格納したい

Whether you're a brand new Redux user setting up your first project, or an experienced user who wants to simplify an existing application, Redux Toolkit can help you make your Redux code better.

TypeScriptと一緒に使う場合
特段型定義ファイルを別途importする必要はないかな

reduxとlocal storageの紐付けに使えそうなライブラリ
redux-persistがstar数多そう
redux-persitst、あんまメンテされてない?
redux-localstorageも最新コミット結構前だな
nextjsのexampleにredux-persistの例もあるしredux-persist使うかな
サンプルの実装もここみる

reduxのディレクトリ構成
今回だとreduxに入れるのはuser情報とかグローバルな情報だけだし
ducksのこのパターンが一番良きかな
modules/
├ component1/
| ├ reducer.js
| ├ actions.js
| └ types.js
└ component2/
├ reducer.js
├ actions.js
└ types.js

詳細の実装はここを参考にする


redux-toolkitでredux-persist設定する場合

redux-persist failed to create sync storage. falling back to noop storage.
が出る問題

react-reduxのuseSelector

導入手順
yarn add @reduxjs/toolkit redux-persist react-redux
yarn add -D @types/react-redux

実際に実装したコード

ざっくりイメージ
- @reduxjs/toolkitでstateの管理
- react-reduxでreactとbindしてる

一通りやりたい実装はできたけど、ここら辺の機能も読んどく