how to fetch textbox input and give it to axios in react native i want to fetch data from input and give it to email and password in Axios

Viewed 342

how to fetch textbox input and give it to Axios in react native I want to fetch data from input and give it to email and password in Axios

[how to fetch textbox input and give it to Axios in react native I want to fetch data from input and give it to email and password in Axios

This is my code

import React, {useState} from 'react';
import {View,Text, TextInput, Button} from 'react-native';
import axios from 'axios';
    const NewsCard = ()=>{
       const[name ,setName] = useState('namesssssssss')
        return(       
            <View>   
                <Text>{name}</Text> 
                <TextInput onChangeText={(val)=>setName(val)}> </TextInput>
                <Button onPress={ ()=>
    axios.post('http://10.0.2.2:5000/api/admin/register',
    {
      email: 'ABC@SpeechGrammarList.com',
      password: 'Flintstone',
    })
    .then(function (response) {
      // handle success
      console.log(response.data);
    })
    .catch(function (error) {
      // handle error
      console.log(error);
    })
    .then(function () {
    })
               } title="Click"></Button>
            </View>   
        )
    }
    
    export default NewsCard
]
1 Answers
  const [email, setEmail] = useState("");
  const [password, setPassword] = useState("");


        <TextInput
          style={styles.inputText}
          autoCorrect={false}
          autoCapitalize="none"
          keyboardType="email-address"
          onChangeText={ (text) => setEmail(text)}
          value={email}
        />

        <TextInput
          style={styles.passwordTextInput}
          secureTextEntry={hidePass ? true : false}
          autoCorrect={false}
          autoCapitalize="none"
          onChangeText={(pswrd) => setPassword(pswrd)}
          value={password}
        />

  useEffect( () => {
    axios.post('YOUR URL', {
      email: email,
      lastName: password
    })
    .then(function (response) {
      console.log(response);
    })
    .catch(function (error) {
      console.log(error);
    });
  }, email, password);
Related