Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

111
Visualizações
Render Item in Agenda using database data - React Native

I'm trying to show the items I get from my database in the calendar, everything is working fine (maybe not), but in short I got the data from the database with an array and then I converted it to an object (because the calendar only accepts objects), but it doesn't show anything and it doesn't give an error either


import React, { useEffect, useState } from 'react'
import { StyleSheet, View, Text } from 'react-native'
import { LocaleConfig, Agenda } from 'react-native-calendars'
import DateTimePicker from 'react-native-modal-datetime-picker';

import { getAuth } from 'firebase/auth';
import { getDatabase, ref, onValue, set, push, get, child } from 'firebase/database';


const Calendario = () => {
 const dbRef = ref(getDatabase());
 const data = []
 var obj = {}

// getting data from the database

  useEffect(() => {
    getInDB()
  } ,[])

  const getInDB = () => {
    get(child(dbRef, 'users/' + app.currentUser.uid)).then((snapshot) => {
        snapshot.forEach(childsnap => {
          let dateD = childsnap.child("date").val()
          let titleD = childsnap.child("title").val()
          let dtsD = childsnap.child("details").val()

          // "yyyy-MM-dd": [{any: "whatever", any2: "whatever"}],
          data.push({
            [dateD] : [{ title: titleD, details: dtsD }],
          });

        })
        obj = Object.assign({}, ...data)
        console.log(obj)
    })
  }

  const renderItem = (item) => {
    return(
        <View style={styles.itemContainer}>
            <Text style={styles.textInf}>{item.title}</Text>
            <Text style={styles.textInf}>{item.details}</Text>
        </View>
    )
  }

 return (
  <>
   <Agenda
   items={obj}
   renderEmptyDate={() => {
    return <View />;
   }}
   renderEmptyData={() => {
    return <View />;
   }}
   selected={new Date()}
   minDate={null}
   renderItem={renderItem}
   markingType="custom"
   />
  </>
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to use state and set it or otherwise your component will not be rerendered with the new data.

Furthermore, the Agenda component expects an object. By using data as an array and the spread operator, we won't get the desired result.

You can implement this correctly as follows.

...
const [obj, setObj] = useState({});
...

const getInDB = () => {
    get(child(dbRef, 'users/' + app.currentUser.uid)).then((snapshot) => {
        const temp = {}
        snapshot.forEach(childsnap => {
          let dateD = childsnap.child("date").val()
          let titleD = childsnap.child("title").val()
          let dtsD = childsnap.child("details").val()

          Object.assign(temp, {dateD: [{ title: titleD, details: dtsD }]})

        })
        setObj(temp)
    })
  }

I have implemented a little snack.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda