import {
View,
Text,
Button,
TextInput,
ScrollView,
StyleSheet,
} from "react-native";
import DateTimePicker from "@react-native-community/datetimepicker";
import React, { useState } from "react";
import { collection, addDoc } from "firebase/firestore";
export const CreateTaskScreen = () => {
const [state, SetState] = useState({
title: "",
description: "",
date: new Date(),
});
const SetData = (key, value) => {
SetState({
...state,
[key]: value,
});
};
const HandlePress = async () => {
await addDoc(collection(db, "tasks"), {
title: state.title,
description: state.description,
date: state.date,
});
};
return (
<View>
<Text>Crear tarea</Text>
<TextInput
placeholder="Title"
onChangeText={(value) => SetData("title", value)}
></TextInput>
<TextInput
placeholder="Description"
multiline
numberOfLines={4} // Adjust the number of lines as needed
onChangeText={(value) => SetData("description", value)}
></TextInput>
<DateTimePicker
style={{ width: 200 }}
date={new Date()}
mode="date"
placeholder="select date"
format="YYYY-MM-DD"
display="default"
onChange={(event, selectedDate) => {
const currentDate = new Date(selectedDate);
SetData("date", currentDate);
}}
></DateTimePicker>
<Button title="Save" onPress={HandlePress}></Button>
</View>
);
};
字符串
问题似乎与DateTimePicker组件处理日期值的方式有关。错误似乎来自DateTimePicker,dateTimePicker组件接收到无效或缺失的值prop。值prop应表示当前或选定的日期/时间,并且必须是有效的JavaScript Date对象
1条答案
按热度按时间clj7thdc1#
您没有在DatePicker-Component中提供“value”属性,而是使用了“date”属性。
字符串