React Native(expo)错误函数.then.catch(为什么我收到TypeError:undefined不



我已经实现了以下函数。

async function login(){
await signInWithEmailAndPassword (auth, email, input)
.then(value=>{
console.log('login ok')
navigation.reset({
index: 0,
routes: [{name:'Home'}]
})
.catch(error => console.log(error));
})
};

它抛出以下错误。

TypeError: undefined is not an object (evaluating 'navigation.reset({
index: 0,
routes: [{
name: 'Home'
}]
}).catch')

代码正在做它应该做的事情,但我仍然收到上面的错误。

这里出了什么问题?

const yourScreen=({navigation})=>{//<-- that's what you need 
//...
async function login(){
await signInWithEmailAndPassword (auth, email, input)
.then(value=>{
console.log('login ok')
navigation.reset({
index: 0,
routes: [{name:'Home'}]
})
.catch(error => console.log(error));
})
};
//...

}
export default yourScreen;

import { useNavigation } from '@react-navigation/native'
const yourScreen=()=>{
const navigation = useNavigation();//<-----
//...

最新更新