无法将参数传递给功能组件之间的路由

时间:2021-02-14 15:21:57

标签: reactjs react-native react-navigation

我在这样的单独文件夹/文件中有两个功能组件

第一个:

export const Inscription = ({ navigation, route }) => {
    // ...    
    function _InscDrog(apiName) {
        InscDrog(apiName).then(data => {
            setResp(data);
            setIsLoading(false);
            if (data.success) {
                navigation.push("Mdp", { phone: '0600000000', }) // this is how I pass params
            } else {
                console.log('success false', JSON.stringify(data));
            }
        })
    }
    //...
    return (
        <View
            style={[Styles.container, { backgroundColor: theme.mainColor }]}>
            {/* ... */}
            <TouchableOpacity
                onPress={() => _InscDrog('Inscription.php',)}
                style={Styles.buttonLogin}>
                <Text style={Styles.buttonLoginTitle}>Check</Text>
            </TouchableOpacity>
            {/* ... */}
        </View>
    );
};

第二个:我必须在哪里获取参数

export const Mdp = ({ navigation, route }) => {
    // ...    
    console.log(JSON.stringify(route), '>> props');
    //{"key":"Mdp-Ju0lgXVp1JjhleQ3PuTbS","name":"Mdp","params":{}} >> props

    //...
    return (
        <View
            style={[Styles.container, { backgroundColor: theme.mainColor }]}>
            {/* ... */}
        </View>
    );
};

正如您所看到的,如果我记录 routeparams 对象是空的,我不知道我是否无法传递参数或无法阅读主题。

1 个答案:

答案 0 :(得分:0)

试试这个:

# A tibble: 27 x 6
      id sex      d8   d10   d12   d14
   <dbl> <chr> <dbl> <dbl> <dbl> <dbl>
 1     1 F      21    20    21.5  23  
 2     2 F      21    21.5  24    25.5
 3     3 NA     NA    24    NA    26  
 4     4 F      23.5  24.5  25    26.5
 5     5 F      21.5  23    22.5  23.5
 6     6 F      20    21    21    22.5
 7     7 F      21.5  22.5  23    25  
 8     8 F      23    23    23.5  24  
 9     9 F      NA    21    NA    21.5
10    10 F      16.5  19    19    19.5
# ... with 17 more rows

source