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 ...
随机推荐
- WScript.Shell 与 Shell.Application 的不同
本文主要对比,VBScript 中 CreateObject("WScript.Shell") 和 CreateObject("Shell.Application&quo ...
- windows找不到文件gpedit.msc处理方法
新建一个txt,输入 @echo offpushd "%~dp0"dir /b C:\Windows\servicing\Packages\Microsoft-Windows-Gr ...
- Nginx是什么东东?
Nginx的产生 没有听过Nginx?那么一定听过它的"同行"Apache吧!Nginx同Apache一样都是一种WEB服务器.基于REST架构风格,以统一资源描述符(Unifor ...
- 磅日波浪分析4H 20190927
磅日的短线调整预计在132结束 目前已显现出ABC调整末端. 未来预计开启第五浪升势 破前期反弹高点.
- Vue 里面对树状数组进行增删改查 的方法
[{"id":"5e4c3b02fc984961a17607c37712eae0", "optLock":0, "parentId ...
- Docker基础修炼1--Docker简介及快速入门体验
本文作为Docker基础系列第一篇文章,将详细阐述和分析三个问题:Docker是什么?为什么要用Docker?如何快速掌握Docker技术? 本系列文章中Docker的用法演示是基于CentOS7进行 ...
- eolinker测试增强
地址:https://www.eolinker.com Chrome: https://chrome.google.com/webstore/detail/eolinker/mdbgchaihbacj ...
- C++判断输入是否为double
C++判断输入是否为double 之前写过了Python如何判断输入字符串是否为数字,但是Python是弱类型语言,相比之下C++这种强类型语言判定难度更大. Python判断输入字符串是否为数字的方 ...
- 搭建环境-Eclipse配置Tomcat创建Servlet总结
Descripton:Web开发:Eclipse的下载与安装,Tomcat下载和结合Eclipse的使用,Eclipse使用Servlet[记录下总结下] 一.Eclipse的下载与安装 下载地址 注 ...
- 在MAC上如何使用SQL Server
由于小编在这学期要学习数据库原理这门课程,需要用到SQL Server,然而大家都知道SQL Server目前是只能在Windows上使用,我们在mac电脑上如何使用呢?我们可以借助目前比较火的Doc ...