Estoy tratando de actualizar estas options en Firestore:
ingrese la descripción de la imagen aquí
Para editar la category , la actualiza con éxito. Pero para la matriz de options , este es el error que muestra:
TypeError no detectado: las opciones no son una función
const [category, setCategory] = useState([]); //useEffect to get all of the categories const [options, setOptions] = useState([]); const [edit, setEdit] = useState(); const handleSubmit = async (e) => { e.preventDefault(); const ref = doc(db, "category", state); await updateDoc(ref, { category: edit, }); console.log("updated"); };formularios
Estoy usando un defaultValue para mostrar el valor inicial que se guardó en Firestore.
{category && category.map((category, index) => ( <form onSubmit={handleSubmit}> <TextField defaultValue={category.cat} type="text" value={categoryEdit} fullWidth onChange={(e) => setCategoryEdit(e.target.value)} /> {category.options.map((i) => ( <TextField type="text" defaultValue={i} variant="outlined" fullWidth value={options(i)} onChange={(e) => setOptions(e.target.value(i))} /> ))} </> )} <Button type="submit">Submit</Button> </form> ))}Esto no tiene nada que ver con la actualización de Firestore.
options es una matriz, pero aquí la estás llamando como una función usando paréntesis:
value={options(i)}Si desea indexar la matriz, use corchetes, no paréntesis.
value={options[i]}