Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to pass parametrs to api?reactjs

here is my target …..the values come from login (it can be anything)->
for ex
email:’aaaa@gmail.com’
password:’12345678′

i should take username until "@" and pass it to api as a username.

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);
    }
}

if it can help here is my link
https://codesandbox.io/s/charming-jang-py0mu?file=/src/auth/actions/userActions.js

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I think this can do the job (using template literals) :

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading