React
约 2 分钟阅读
- suspense 通过 throw prmies 实现
- vigzmv/react-promise-suspenseGitHub 文件vigzmv/react-promise-suspense/lib/index.tssuspense 通过 throw prmies 实现 · vigzmv/react-promise-suspense · 带 key 的组件不会被复用 demo · 可以避免 props 变化问题 · 更适用于 memo · Context Selectors react#20646笔记:React
# 常用工具
npm i -g react-native-cli code-push-cli
# Redux
npm i --save redux redux-thunk
npm i --save-dev remote-redux-devtools
# Redux Native
npm i --save react-redux redux-persist
# Native
npm i --save react-base react-native-vector-icons依赖包react-native-clinpm 包react-native-cliNPMcode-push-clinpm 包code-push-cliNPMreduxnpm 包reduxNPMredux-thunknpm 包redux-thunkNPMremote-redux-devtoolsnpm 包remote-redux-devtoolsNPMreact-reduxnpm 包react-reduxNPMredux-persistnpm 包redux-persistNPMreact-basenpm 包react-baseNPMreact-native-vector-iconsnpm 包react-native-vector-iconsNPM
- 带 key 的组件不会被复用 demo
- 可以避免 props 变化问题
- 更适用于 memo
- Context Selectors react#20646GitHub PRfacebook/react#20646
- React.memo + useContext react#15156GitHub Issuefacebook/react#15156
React components naming convention
[Domain]|[Page/Context]|ComponentName|[Type]- Domain
- 业务域名词 - 划分模块或产品
- Page/Content
- 使用的位置上下文 - 最近上下文
- 例如 Sidebar
- ComponentName
- 组件目的,用于做什么的
- Type
- View - 视图,只展现数据
- Button
- 表单类 - Input、Upload
- Component - HOC 类组件,原有组件保持原有名字
- Container - 容器类,提供交互接口数据
- Domain
Presentational and Container Components
- presentational
- 关心 “看起来怎么样”
- 可能包含 Presentational 和 Container 组件
- 通常包含 DOM/元素/Markup/样式
- 通常允许 children 属性传递
- 无外部依赖 - Redux、REST、API
- 不关心数据加载和修改
- 通过 props 接受属性和回调
- 通常没有自己的状态 - 有也只是 UI 状态
- 通常为函数组件
- 例如 Page, Sidebar, Story, UserInfo, ListItem
- container
- 关心 “逻辑如何运作”
- 除了封装基本不包含元素,没有自己的样式
- 为 presentational 或其他 container 提供样式和行为
- 会与 状态/Redux 交互,为 presentational 提供回调
- 通常有状态和数据源
通常配合 HOC - React Redux connect(), Relay createContainer(), Flux Utils Container.create()- 例如 UserPage, FollowersSidebar, StoryContainer, FollowedUserList.
- 其他划分点
- 有状态、无状态
- 累、函数
- Pure、Impure
FAQ
命名
关联信息
反向链接、本文链接的其他页面和外部资料。
反向链接
- Web Awesome笔记 · react
https://www.c82.net/iconography/ · https://www.photopea.com/ · ryohey/signal · MIT, TS · Online MIDI Editor: signal · http://oskarstalberg.com/Townscaper/
参考资料
GitHub4 条
- facebook/react#15156github.com/facebook/react/issues/15156
- facebook/react#20646github.com/facebook/react/pull/20646
- vigzmv/react-promise-suspense/lib/index.tsgithub.com/vigzmv/react-promise-suspense/blob/master/lib/index.ts
- wojtekmaj/react-lifecycle-methods-diagramgithub.com/wojtekmaj/react-lifecycle-methods-diagram
其他外链3 条
- codesandbox.io/s/react-keyed-reuse-u2to6codesandbox.io/s/react-keyed-reuse-u2to6
- medium.com/@dan_abramov/7ca2f9a7c7d0medium.com/@dan_abramov/7ca2f9a7c7d0
- medium.com/@wittydeveloper/b50303551505medium.com/@wittydeveloper/b50303551505