Amir Ebr
Amir Ebr

Reputation: 15

how to fix '.then is not a function' in react native

I have an error in react native that says '.then is not a function' in this code where I use .this in .then(()=>{this.manageAccess()}) What can I do?

Or tell me if there is a replacement for .this

export function signIn(data) {
 const request = axios({
    method:"POST",
    url:SIGNIN,
    data:{
        email: data.email,
        password: data.password,
        returnSecureToken:true
      },
    headers:{
        "Content-Type":"application/json"
      }
   }).then( response => {
    return response.data
    }).catch(e =>{
    return false
    });

   return {
    type: SIGN_USER,
    payload: request
   }
}

class LoginForm extends Component {

   manageAccess = () => {
    if(!this.props.User.userData.uid){
        this.setState({hasErrors:true})
    } else {
        setTokens(this.props.User.userData,()=>{
            this.setState({hasErrors:false});
            this.props.navigation.navigate('Dashboard')

        })
    }
};

  submitUserHandler = ()=>{
    let isFromValid = true;
    let formToSubmit= {};
    if(isFromValid){
        if(this.state.type === "Login"){
            this.props.signIn(formToSubmit).then(()=>{
                this.manageAccess()
            })
        } 
    }
  };
}

Upvotes: 0

Views: 957

Answers (1)

charlietfl
charlietfl

Reputation: 171669

Your signIn() function returns an object where the request object is in the payload property

Try changing to

this.props.signIn(formToSubmit).payload.then(...

Upvotes: 1

Related Questions