我正在尝试使用自定义钩子管理表单,所以我有这个代码
FormHook.tsx:
import { useState } from 'react';
interface ICampos {
name: string;
email: string;
password: string;
}
const useForm = (initialState: ICampos) => {
const [values, setValues] = useState(initialState);
const handleInputChange = ({ target }: any) => {
setValues({
...values,
[target.name]: target.value
})
};
return [values, handleInputChange];
}
export default useForm
Run Code Online (Sandbox Code Playgroud)
FormWithCustomHook.tsx:
import React from 'react'
import './effects.css'
import useForm from '../../hooks/useForm';
interface ICampos {
name: string;
email: string;
password: string;
}
const FormWithCustomHook = () => {
const …Run Code Online (Sandbox Code Playgroud)