Home > Back-end >  React Native - Why isn't the function getting called?
React Native - Why isn't the function getting called?

Time:10-23

I have a function inside another function that won't get called.

First function:

const getToken = dispatch => async () => {
  try {
    GoogleSignin.configure({
      webClientId: 'XXXX',
      iosClientId: 'XXXX',
    });
    const {idToken} = await GoogleSignin.signIn();
    const googleCredential =
      firebase.auth.GoogleAuthProvider.credential(idToken);
    const userCredential = await firebase
      .auth()
      .signInWithCredential(googleCredential);
    const token = userCredential.user.uid;
    secondFunction(token);
  } catch (err) {
    dispatch({
      type: 'error_1',
      payload: 'error',
    });
  }
};

2nd function:

const secondFunction = dispatch => token => {
  console.log('second function called');
  try {
    axios.post(url, token).then(res => {
      console.log(res.data);
      const response = res.data;
  } catch (err) {
    dispatch({
      type: 'error_1',
      payload: 'error',
    });
  }
};

might be something simple I'm not getting. Would appreciate any help!

CodePudding user response:

Should be

secondFunction(dispatch)(token)

Because your console.log was inside nested function

  • Related