Declare incidents as an empty array

This commit is contained in:
Ray 2023-12-28 14:24:56 +00:00 committed by GitHub
parent c77da414f1
commit 151e17675c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -34,6 +34,7 @@ export function MyForm(props) {
const [date, setDate] = useState(''); const [date, setDate] = useState('');
const [context, setContext] = useState(''); const [context, setContext] = useState('');
const [selectedOptions, setSelectedOptions] = useState([]); const [selectedOptions, setSelectedOptions] = useState([]);
const [incidents, setIncidents] = useState([]); // Declare incidents as an empty array
// Create a function to handle the checkbox changes and update the state accordingly. // Create a function to handle the checkbox changes and update the state accordingly.
const handleCheckboxChange = (event) => { const handleCheckboxChange = (event) => {
@ -50,9 +51,9 @@ export function MyForm(props) {
const submitHandler = async (event) => { const submitHandler = async (event) => {
event.preventDefault() event.preventDefault()
const incidents = { setSubmitter, setDate, setContext, setSelectedOptions } const incidentsData = { submitter, date, context, selectedOptions } // Use the state variables directly
const col = collection(db, `incidents/${props.incidentId}/incident_logs`) const col = collection(db, `incidents/${props.incidentId}/incident_logs`)
const ref = await addDoc(col, incidents) const ref = await addDoc(col, incidentsData)
console.log(ref) console.log(ref)
} }