zoukankan      html  css  js  c++  java
  • 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)
    }
  • 相关阅读:
    selenium 18种元素定位方法
    python3+selenium配置可能报错记录
    adb+monkey压力测试入门
    appscan使用教程(全)
    appium---android元素定位
    QTP自动化测试
    postman Could not get any response。
    Jmeter接口测试+压力测试
    Android 偏门xml属性
    CrashHandler
  • 原文地址:https://www.cnblogs.com/Nyan-Workflow-FC/p/11230813.html
Copyright © 2011-2022 走看看