Я пытаюсь загрузить некоторые данные из своей базы данных в Firestore, но не понимаю, почему переменная загружает из нее дублированные документы.
В Firestore у меня есть коллекция с двумя элементами, test1 и test2, как вы можете видеть на скриншоте ниже.
I'm loading the full collection in my function seleccionarTest(), and I'd like to load var tests with the two docs (test1 and test2) that I will use later in a Touchable Flat List.
See the function:
export default function AsignarTest({route, navigation}){
console.log("Entrando en asignar test");
const {usuario} = route.params;
const [animacion, setAnimacion] = useState(true);
const [tests, setTests] = useState([]);
const db = firestore();
function seleccionarTests(){
db.collection("test").get()
.then((querySnapshot) =>{
var i=0;
querySnapshot.forEach((documentSnapshot)=>{
tests.push({id:documentSnapshot.id, datos: documentSnapshot.data()});
});
setAnimacion(false);
console.log(tests);
return;
}).catch((error)=>{
console.log(error);
});
}
//Gestionamos cuando el usuario selecciona una peluqueria
const gestionarClick = (id)=>{
//Todo
console.log(id);
}
const p = seleccionarTests();
return(
item.id}
data={tests}
renderItem= {({item})=> (
{gestionarClick(item.id)}}>
{item.id}
)} />
);
}
Unfortunately, as you can see in the next screenshot, my var in console.log has 4 documents, (test1, test2, test1, test2) and I can't understand why the docs are duplicated.
Captura del console.log del array de tests
Спасибо за комментарии!