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 ...
随机推荐
- 万字综述,核心开发者全面解读PyTorch内部机制
斯坦福大学博士生与 Facebook 人工智能研究所研究工程师 Edward Z. Yang 是 PyTorch 开源项目的核心开发者之一.他在 5 月 14 日的 PyTorch 纽约聚会上做了一个 ...
- 3分钟学会简单使用Vim
Vim是一款运行在命令行里的文字编辑器,它是Linux人员的标配.在Windows环境下也可以有特别的用处,比如创建没有文件名的文件(.gitignore). Vim的功能十分强大,以至于有一些人对它 ...
- FME中矢量裁剪
- 常见Web安全漏洞--------防盗链
1,防盗链防止盗用自己服务上的东西... 2,XSS服务上有这么一张图: <!DOCTYPE html> <html> <head lang="en" ...
- AI+BI的未来
术语与缩写解释 缩写.术语 解 释 BI 商业智能(Business Intelligence,简称:BI),又称商业智慧或商务智能,指用现代数据仓库技术.线上分析处理技术.数据挖掘和数据展现技 ...
- 【python系统学习12】函数
函数 函数是一堆组织好的.可重复利用的.用来实现某一功能的代码. python中的input().print().type().bool().len()等都是函数.且是python的内置函数. 我们也 ...
- MATLAB——元胞数组
一. 1.元胞数组的创建 >> a={;ones(,),:} a = ] [2x3 ;ones(,),:} >> b=[{};{ones(,)},{:}] b = ] [2x3 ...
- 原来rollup这么简单之 tree shaking篇
大家好,我是小雨小雨,致力于分享有趣的.实用的技术文章. 内容分为翻译和原创,如果有问题,欢迎随时评论或私信,希望和大家一起进步. 分享不易,希望能够得到大家的支持和关注. 计划 rollup系列打算 ...
- C Cow XOR 奶牛异或
时间限制 : 10000 MS 空间限制 : 65536 KB 问题描述 农民约翰在喂奶牛的时候被另一个问题卡住了.他的所有N(1 <= N <= 100,000)个奶牛在他面前排成一 ...
- 徒手生撸一个验证框架,API 参数校验不再怕!
你们之中大概率早已练就了代码的拷贝.粘贴,无敌的码农神功,其实做久了业务功能开发,练就这两个无敌神功,那是迟早的事儿.今天先抛一个小问题,来打通你的任督二脉,就是很好奇的问一下:业务功能开发中,输入参 ...