如何使用ReactJS setState保存来自Axios API调用的错误响应?

我试图为React功能组件使用setState(在这种情况下为setErrors),以便将错误响应从axios帖子保存到我的api。我想保存该响应,以便在注册页面上将其显示给用户。即API响应为{电子邮件:“此电子邮件已被使用”},并在“反应注册”页面上的电子邮件输入下方显示。

问题是调用setErrors之后会记录一个空对象。因此,我很确定我没有正确设置状态。

SignupPage.js

const signup = () => {
        console.log(`Account created ${inputs.handle}, ${inputs.email}`);
    }
const {inputs, errors, handleInputChange, handleSubmit} = useSignUpForm(signup);

CustomHooks.js

const useSignUpForm = (callback) => {

    const [inputs, setInputs] = useState({});
    const [errors, setErrors] = useState({});

    const handleSubmit = (event) => {
        if (event) {
          event.preventDefault();
          console.log(inputs);
          axios.post('/student/signup', inputs)
          .then((res) => {
            console.log(res.data);
            this.props.history.push('/');
          })
          .catch(err => {
            console.log(err.response.data);
            setErrors({
                ...errors,
                message: err.response.data
            });
            console.log(errors);
          });
        }
        callback();
    }
    const handleInputChange = (event) => {
        event.persist();
        setInputs(inputs => ({...inputs, [event.target.name]: event.target.value}));
    }
    return {
        handleSubmit,
        handleInputChange,
        inputs,
        errors
    };
  }
export default useSignUpForm;