我有一個 React Native 應用程序,成員可以在其中更改他們的公司電話號碼,但是一旦用戶保存并關閉該屏幕,該電話號碼更改就不會持續(xù)存在。有一個警告說:失敗的道具類型:道具 businessPhoneNumberChanged 在 BusinessDetailsForm 中被標記為必需,但其值未定義。我想知道這是否與BusinessDetailsForm作為功能組件的事實有關,這意味著必須有一個父組件將 props 傳遞給它,而且我沒有在任何地方找到它的父組件:這是功能組件:import React from 'react';import {View, Text, ScrollView, TouchableOpacity} from 'react-native';import Icon from 'react-native-vector-icons/MaterialIcons';import {v2Colors, v2Fonts, v2ButtonStyles} from 'theme';import {Divider, Input, CheckBox} from 'common-components';import {TextButton} from 'react-native-material-buttons';import PropTypes from 'prop-types';import {ScaledSheet} from 'react-native-size-matters';const propTypes = { businessName: PropTypes.string.isRequired, businessNameChanged: PropTypes.func.isRequired, businessPhoneNumber: PropTypes.string, businessPhoneNumberChanged: PropTypes.func.isRequired, businessWebsite: PropTypes.string.isRequired, businessWebsiteChanged: PropTypes.func.isRequired, changeBussinessAddressNavigation: PropTypes.func.isRequired, changeMailingAddressNavigation: PropTypes.func.isRequired, errors: PropTypes.object, joinDate: PropTypes.string, renewDate: PropTypes.string, saveChanges: PropTypes.func.isRequired, shortBusinessAddress: PropTypes.object.isRequired, shortMailingAddress: PropTypes.object, toggleSameAddresses: PropTypes.func, useSameAddress: PropTypes.bool,};const BusinessDetailsForm = props => ( <View style={styles.container}> <ScrollView contentContainerStyle={{paddingBottom: 56}}> <View style={styles.titleContainer}> <Text style={styles.title}>{'Business Information'}</Text> </View> <View style={styles.inputContainer}> <View style={styles.icon}>我沒有看到 this 的父組件businessPhoneNumberChanged。當我使用 props 時,我會將其設為BusinessDetailsForm基于類的組件,但我不確定這是否是問題所在。我總是假設人們知道他們在做什么。道具類型的作用對我來說也不是 100% 清楚,因為我沒有使用它太多。所以拋開我自己的理論,為什么businessPhoneNumberChangedundefined的價值?
React Native:失敗的道具類型:道具 businessPhoneNumberChanged
森林海
2021-06-01 10:57:51