如何将参数传递给 api? react js

how to pass parametrs to api?reactjs

这是我的目标 .....这些值来自登录(可以是任何东西)-> 对于前 电子邮件:'aaaa@gmail.com' 密码:'12345678'

我应该使用直到“@”的用户名并将其作为用户名传递给api。

export const loginUser = (values, history, setFieldError, setSubmitting) => {
    console.log("values from login", values)

    //here i take the email split value and take as user name 
    const username = values.email.split("@")[0]
    console.log("user name", username)

     //now i should pass the username as a name parametr to api

    return () => {
        axios.get('https://api.agify.io/?', values
        ).then((response) => {
            //if res ok should redirect it 
            console.log("response", response)
            // history.push("/user")
        }).catch(error => console.error(error))
        setSubmitting(false);
    }
}

如果它能帮上忙,这是我的 link https://codesandbox.io/s/charming-jang-py0mu?file=/src/auth/actions/userActions.js

我认为这可以完成这项工作(使用模板文字):

axios.get(`https://api.agify.io/?name=${username}`)