随笔分类 - React
摘要:input在输入时,控制台出现 warning 意思是: Input 组件从一个非受控组件变成了一个受控组件。 造成这个问题的原因是:初始化时,Input 组件的value值为undefined。 所以,要解决该问题,我们只要在初始化时,Input 组件的value值为undefined时赋值一个空
阅读全文
摘要:@reduxjs/toolkit 场景:获取产品详情 @reduxjs/toolkit 依赖了redux、redux-thunk,所以使用toolkit就不需要额外下载redux,意味着可以再多个框架使用,但是并没有react-redux,所以仍然需要安装react-redux。依赖了redux-t
阅读全文
摘要:场景:切换语言、请求产品列表 src/index.tsx import React from 'react' import ReactDOM from 'react-dom' import { Provider } from 'react-redux' // react-redux 利用上下文con
阅读全文
摘要:场景:切换语言、请求产品列表 src/index.tsx import React from 'react' import ReactDOM from 'react-dom' import { Provider } from 'react-redux' // react-redux 利用上下文con
阅读全文
摘要:场景:切换语言 使用react-redux的步骤 安装 react-redux依赖 在src/index.tsx中引入 react-redux中的Provider, store, 使用Provider,并加载store数据仓库 react-redux使用react的context上下文,提供一个Pr
阅读全文
摘要:场景:切换语言 使用react-redux的步骤 安装 react-redux依赖 在src/index.tsx中引入 react-redux中的Provider, store, 使用Provider,并加载store数据仓库 react-redux使用react的context上下文,提供一个Pr
阅读全文
摘要:场景:切换语言 安装redux依赖包 npm i redux --save 新建目录 新建目录:src/redux、src/redux/language 新建文件:src/redux/store.ts、src/redux/language/actionCreators.ts,src/redux/la
阅读全文
摘要:redux redux使用步骤 使用步骤: 定义一个 reducer 函数 (根据当前想要做的修改返回一个新的状态) 使用createStore方法传入 reducer函数 生成一个store实例对象 使用store实例的 subscribe方法 订阅数据的变化(数据一旦变化,可以得到通知) 使用s
阅读全文
摘要:react项目使用i18n进行国际化封装 安装 npm i i18next react-i18next --save 配置i18n: 在根目录新建一个目录i18n 在i18n目录添加en.json、zh.json { "footer": { "detail" : "版权所有 @ React 旅游网"
阅读全文
摘要:antd 样式主题自定义 安装antd组件库 npm i antd --save 在index.tsx中引入样式的less文件(引入less,为了自定义主题色) import 'antd/dist/antd.less' 使用craco:Create React App Configuration O
阅读全文
摘要:React 项目的css-in-js(简称JSS) TS的定义声明 文件名为:*.d.ts 只包含类型声明,不包含逻辑 不会被编译,也不会被webpack、vite打包 1. css modules(配置typescript-plugin-css-modules完成类型申明) 定义css的类型申明文
阅读全文