I have tried other similar questions on StackOverflow but I found no solution to my problem.
Problem is that I am making an API call inside a function, I am also using async/await for this call but the function still returning {"_U": 0, "_V": 0, "_W": null, "_X": null}.
From this and other questions on StackOverflow, I came to know that this problem arises because the function not working properly with API.
import { firebase } from '@react-native-firebase/firestore';
async function userLogin(name, password) {
await firebase.firestore().collection('users').where("name", "==", name).where("password", "==", password).get()
.then((response) => {
console.log('Response:')
if (response.docs === []) {
return
} else {
return true
}
}).catch(err => console.error(err));
}
const initialState = {
loggedIn: false,
name: '',
}
const rootReducer = (state = initialState, action) => {
if (action.type === 'LogIn') {
const data = userLogin(action.name, action.password)
if (data) {
return {
...state,
name:action.name,
loggedIn:false
}
}
else {
console.log(4);
return {
...state,
name: 'aName',
loggedIn:true
}
}
}
return state;
}
export default rootReducer;