我看教程,是:
/store/index.ts
/store/modules/a.ts
/store/modules/b.ts  
a.ts 和 b.ts 中,分别有各自的 action,reducer 。 这样的目录结构。
我以前做 App 的习惯相当于是:
/store/index.ts
/modules/A/a.ts 、A.modules.scss 、A.tsx...
/modules/B/b.ts 、B.modules.scss 、B.tsx...  
喜欢把和 A 有关的东西,尽量都塞在 A 里面。
不过毕竟其实 App 没有这个 /store/index.ts 。  
前者的优势在?
单纯的习惯问题?
|  |      1zqlcrow OP 举个例子:   购物车。 1 、购物车相关的代码,分别分散在: actions/cartActions.js components/Cart.js reducers/cartReducer.js 2 、我多年 app 的习惯是,购物车相关的代码,尽量全部在 cart 模块(目录)中。 cart/cartActons.js cart/cartReducers.js cart/Cart.js | 
|  |      2sweetcola      2023-04-18 15:27:42 +08:00 现在官方是推荐使用 [RTK]( https://redux-toolkit.js.org/usage/usage-guide),React-Redux 已经不是推荐使用的方式了。 目录只要能通过名称看得懂这个目录里装着什么就可以了。 我的话是直接 /redux/store.ts /redux/slice/*Slice.ts | 
|      3shaozelin030405      2023-04-18 15:32:28 +08:00 直接 reducer ,不需要 action 。之后引入 redux-saga ,可以 reducer 一起放 effect | 
|      4hervey0424      2023-04-18 15:42:51 +08:00 直接用 mobx 吧, 对 ts 支持更好 | 
|  |      5wu67      2023-04-18 15:52:07 +08:00 建议 recoil. 概念少, 使用简单. 我主用 vue 的, 去年随便看看文档就能开写了. https://recoiljs.org/zh-hans/docs/introduction/core-concepts | 
|  |      6zhwithsweet      2023-04-18 17:41:18 +08:00 via iPhone jotai zustand. Redux 千万别用 | 
|  |      7sl0000      2023-04-18 18:29:13 +08:00 我看 redux 都头疼 | 
|  |      8ruoxie      2023-04-18 18:43:56 +08:00 via iPhone 求求别再用 redux 了,为什么想不开 | 
|      9hgaogao      2023-04-18 18:50:09 +08:00 via iPhone @zhwithsweet jotai 都不行吗?听说挺简洁的呀?有什么说法吗? | 
|  |      10zhwithsweet      2023-04-18 18:52:34 +08:00 @hgaogao 我的断句问题;用 jotai 或者 zustand; 千万别用 redux (redux 极其难用 | 
|  |      11linkopeneyes      2023-04-18 22:46:30 +08:00 没什么必要用 redux 除非是老项目维护,其实如果不在乎性能直接 content 就好了,什么库都还是要学概念 | 
|      12zhoupeng199      2023-04-19 09:51:42 +08:00 为啥要用 redux 这么难用的东西,建议 Mobx ,天生面向对象编程 | 
|  |      13karott7      2023-04-19 17:52:13 +08:00 看到这些状态库就头大,一堆概念,我现在都是用 React.createContext + immer 自己封装下,全局一个 Context ,业务使用独自的 Context ; 个人看法,我认为自从 react-router-dom 带来 data-router 功能之后,loader + useLoaderData + useRouteLoaderData 的组合可以直接宣告状态库死亡了,而且 react@18 不是也增加了啥状态管理功能么 | 
|      14humbass      2023-05-04 20:54:35 +08:00 我是 6  年的  vuer ,第一次尝试用 react  做完一个项目,记得刚开始配置 redux  ,花了 1 天基本的  demo  都没跑通,Jotai  基本上 几分钟之内就可以上手。 我觉得阻挡大部分 vue 用户进入 react 的都是这些基础的东西没完善,或者说脚手架做的不好。 |