##LoginScreenからRecordScreenに遷移させるときにパラメータが引き渡せない
下記のようにLoginScreenからRecordScreenに遷移させるとき、パラメータが引き渡せず、
props.route.paramsがundefinedになってしまいます。
どのようにすればuserパラメータをRecordScreenに引き渡せますでしょうか?
問題の箇所を抜粋。 .then(function (user) { navigation.navigate("Record", { currentUser: user }); }) 詳細は下記
LoginScreen
1export default LoginScreen = ({ navigation }) => { 2 const initialEmail = ""; 3 const initialPassword = ""; 4 const [email, esetText] = useState(initialEmail); 5 const [password, psetText] = useState(initialPassword); 6 const onPress = () => { 7 firebase 8 .auth() 9 .signInWithEmailAndPassword(email, password) 10 .then(function (user) { 11 navigation.navigate("Record", { currentUser: user }); 12 }) 13 .catch(function (error) { 14 // Handle Errors here. 15 const errorCode = error.code; 16 const errorMessage = error.message; 17 alert(errorCode); 18 alert(errorMessage); 19 // ... 20 }); 21 }; 22 23 return ( 24 <View style={styles.container}> 25 <Text style={styles.title}>ログイン</Text> 26 <TextInput 27 style={styles.input} 28 value={email} 29 onChangeText={(email) => esetText(email)} 30 autoCapitalize="none" 31 autoCorrect={false} 32 placeholder="Email" 33 /> 34 <TextInput 35 style={styles.input} 36 value={password} 37 onChangeText={(password) => psetText(password)} 38 autoCapitalize="none" 39 autoCorrect={false} 40 placeholder="Password" 41 secureTextEntry={true} 42 /> 43 <TouchableHighlight style={styles.button} onPress={onPress}> 44 <Text style={styles.buttonText}>ログイン</Text> 45 </TouchableHighlight> 46 </View> 47 ); 48};
RecordScreen
1export default RecordScreen = (props) => { 2 3 const { navigation, route } = props; 4 const params = route.params; 5 console.log(navigation); 6 console.log(route); 7 console.log(params); 8 return ( 9 <SafeAreaView style={styles.container}> 10 <TouchableOpacity style={styles.circleButton} onPress={onPress}> 11 <Text style={styles.circleButtonTitle}>+</Text> 12 </TouchableOpacity> 13 </SafeAreaView> 14 ); 15};
下記がログです。
log
1console.log(navigation); 2↓ 3Object { 4 "addListener": [Function addListener], 5 "canGoBack": [Function canGoBack], 6 "dangerouslyGetParent": [Function dangerouslyGetParent], 7 "dangerouslyGetState": [Function anonymous], 8 "dispatch": [Function dispatch], 9 "goBack": [Function anonymous], 10 "isFocused": [Function isFocused], 11 "jumpTo": [Function anonymous], 12 "navigate": [Function anonymous], 13 "pop": [Function anonymous], 14 "popToTop": [Function anonymous], 15 "push": [Function anonymous], 16 "removeListener": [Function removeListener], 17 "replace": [Function anonymous], 18 "reset": [Function anonymous], 19 "setOptions": [Function setOptions], 20 "setParams": [Function anonymous], 21} 22 23console.log(route); 24↓ 25Object { 26 "key": "Record-23v2YUDv-hWZtJX9yj4T2", 27 "name": "Record", 28 "params": undefined, 29} 30 31console.log(params); 32↓ 33undefined 34
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。