我有一个 Formik 表单,我可以在其中获取用户输入并在提交后运行查询。
当我单击搜索按钮时,会呈现一个列表。所有列表项都有自己的按钮。当我第一次单击绿色添加按钮(从列表项中)时,该按钮不起作用。不打印控制台日志的内容。相反,将触发 inputField 的 onBlur 事件。但是,如果我再次单击 + 按钮,则它可以工作并打印 no。此问题在模拟器/手机中可见,而不是在沙箱上的 Web 模式中可见。
export const AddFriendScreen: React.FunctionComponent = () => {
const initialValues: FormValues = {
input: '',
};
const [showFlatList, setShowFlatList] = useState<UsersLazyQueryHookResult>(
'',
);
const handleSubmitForm = (
values: FormValues,
helpers: FormikHelpers<FormValues>,
) => {
loadUsers({
variables: {
where: {
OR: [
{ phoneNumber: newPhoneNumber },],
},
},
});
helpers.resetForm();
};
return (
<SafeAreaView style={styles.safeAreaViewContainer}>
<View style={styles.searchTopContainer}>
<View style={styles.formContainer}>
<Formik
initialValues={initialValues}
onSubmit={handleSubmitForm}
validationSchema={validationSchema}>
{({ handleChange, handleBlur, handleSubmit, values }) => (
<View style={styles.searchFieldContainer}>
<View style={styles.form}>
<FieldInput
handleChange={handleChange}
handleBlur={handleBlur}
value={values.input}
fieldType="input"
icon="user"
placeholderText="E-Mail oder Telefonnummer oder Name"
/>
<ErrorMessage
name="input"
render={(msg) => <ErrorText errorMessage={msg} />}
/>
</View>
<View style={styles.buttonContainer}>
<ActionButton buttonText="Suchen" onPress={handleSubmit} />
</View>
</View>
)}
</Formik>
</View>
<View style={styles.listHolder}>
{data && showFlatList !== null && (
<UsersFoundList
data={data}/>
)}
</View>
</View>
</SafeAreaView>
);
};
小吃展:
https://snack.expo.io/@nhammad/jealous-beef-jerky
[![在此处输入图像描述][1]][1]
编辑:
找到了一种解决方法,但仍然对更简单的解决方案持开放态度。仍然没有弄清楚究竟是什么导致了这个问题。