react: typescript interface useState issue

Posted nyan-workflow-fc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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])

 

以上是关于react: typescript interface useState issue的主要内容,如果未能解决你的问题,请参考以下文章