react: typescript interface useState issue
define interface:
interface ILoginState {
imageId: string;
imageSrc: string;
username: string;
password: string;
verifyCode: string;
}
useState:
const [loginData, setLoginData] = useState(loginState)
update imageId && imageSrc:
setLoginData({
...loginData,
imageId: res.data.id.
imageSrc: res.data.content
})
antd inputchange:
onInputChange(e: FormEvent<HTMLInputElement>) {
const inputName = e.currentTarget.id;
const inputValue = e.currentTarget.value;
setInputData({
[inputName]: inputValue
} as {[key in keyof ILoginState]:ILoginState[key]})
}
antd form onsubmit
<Form onSubmit={handleSubmit.bind(this)}>
add window resizeLitener
const [contentHeight, setHeight]=useState(INTIAL_HEIGHT)
useEffect(()=>{
screenChange();
return () => removeListener()//回调销毁
},[contentHeight]) const screenChange = () => {
window.addEventListener("resize", handleResize)
} const removeListener = () => {
window.removeEventListener("resize", handleResize)
} handleResize =(e)=> {
setHeight(e.target.innerHeight-headerHeight-footerHeight)
}
react: typescript interface useState issue的更多相关文章
- react + typescript 学习
react,前端三大框架之一,也是非常受开发者追捧的一门技术.而 typescript 是 javascript 的超集,主要特点是对 类型 的检查.二者的结合必然是趋势,不,已经是趋势了.react ...
- react: typescript project initialize
Initialize the project create a folder project Now we’ll turn this folder into an npm package. npm i ...
- react typescript jest config (一)
1. initialize project create a folder project Now we'll turn this folder into an npm package. npm in ...
- TypeScript Interface vs Types All In One
TypeScript Interface vs Types All In One TypeScript https://www.typescriptlang.org/docs/handbook/adv ...
- React + Typescript领域初学者的常见问题和技巧
React + Typescript领域初学者的常见问题和技巧 创建一个联合类型的常量 Key const NAME = { HOGE: "hoge", FUGA: "f ...
- 【每天学一点-04】使用脚手架搭建 React+TypeScript+umi.js+Antd 项目
一.使用脚手架搭建项目框架 1.首先使用脚手架搭建React项目(React+TypeScript+Umi.js) 在控制台输入命令:yarn create @umijs/umi-app 2.引入An ...
- React typescript issue
多个输入框发生变化时,setState: this.setState({[e.target.name]: e.target.value} as componentState)
- 使用react搭建组件库:react+typescript+storybook
前期准备 1. 初始化项目 npx create-react-app react-components --template typescript 2. 安装依赖 使用哪种打包方案:webpack/r ...
- react+typescript报错集锦<持续更新>
typescript报错集锦 错误:Import sources within a group must be alphabetized.tslint(ordered-imports) 原因:impo ...
随机推荐
- TensorFlow系列专题(二):机器学习基础
欢迎大家关注我们的网站和系列教程:http://www.tensorflownews.com/ ,学习更多的机器学习.深度学习的知识! 目录: 数据预处理 归一化 标准化 离散化 二值化 哑编码 特征 ...
- Activiti7流程定义
一.什么是流程定义 流程定义是线下bpmn2.0标椎去描述业务流程,通常使用activiti-explorer(web控制台)或 activiti-eclipse-designer 插件对业务流程进行 ...
- 1519: 【USACO】超级书架
1519: [USACO]超级书架 时间限制: 1 Sec 内存限制: 64 MB 提交: 1735 解决: 891 [提交] [状态] [讨论版] [命题人:外部导入] 题目描述 Farmer Jo ...
- 自定义yum仓库
自定义yum仓库 案例4:自定义yum软件仓库 4.1问题 本例要求在CentOS真机上利用RHEL7的光盘镜像文件准 ...
- 【redis】redis
一.redis简介: 1. reids 也是一个 key-value 存储系统,更加确切地说,它已经是一个非关系型数据库. 2. 关系型. SQL语言. 3. 非关系型. key - value. 4 ...
- python 函数--装饰器
一.装饰器 1.为什么要用装饰器? 装饰器的功能:在不修改原函数以及调用方式的情况下对原函数功能进行扩展. 二.开放和封闭原则 1.对扩展是开放的 2.对修改是封闭的 三.装饰器的固有结构 impor ...
- Git mergetool 插件
首先你喜欢使用git命令行操作,可以上网下载Kdiff3安装到你的电脑,然后按下面的操作就可以使用这个工具了. 1. 安装Kdiff3 软件.(最好使用默认路径) 2. 添加kdiff3到git me ...
- python的int float if...else
# 字符串 string 单引号 ‘ ’ 双引号 “ ”-包含的 app = 'dongt woory' 外面单引号里面可以双引号,外面双引号,里面也可以单引号 app ='你是真的“好看”吗' ...
- Alibaba Cloud Linux 2 LTS 正式发布,提供更高性能和更多保障!
在Alibaba Cloud Linux 2(原Aliyun Linux 2)上线一年之际阿里云对外正式发布Alibaba Cloud Linux 2 LTS版本.LTS版本的发布对于Alibaba ...
- PHP程序员的能力水平层次(一)
前言 之前看过很多篇关于服务端工程师和PHP开发者的能力模型介绍,每篇都对能力有侧重点. 下面我们来详细谈谈以开发能力为基准点的PHP程序员的能力水平层次. 层层递进 1.功能开发 这个水平的程序员一 ...