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

89
Visualizações
Efficient way of Converting Timestamp to date from firestore

Good day, I am currently working on a firestore/react app. And I have this form where I set the initial values using spread syntax/operator. Everything is working fine but when I try to store a date value which firestore converts to a timestamp. It crashes my app as it doesn't know how to read it.

My method before was to do it manually. (Setting the initial values then converting the timestamp). But as the form requirements goes complex and needed a lot of date. It becomes harder for me to do it.

    const [targetClient, setTargetClient] = useState([]);

const Data = () => {
    const usersCollectionRef = collection(db, "client");
    onSnapshot(usersCollectionRef, (snapshot) => {
        let userData = []
        snapshot.docs.forEach(doc => {
            userData.push({ ...doc.data(), id: doc.id })
        })
        setTargetClient(userData)
    })
};

useEffect(() => {
    Data();
}, []);

Then I passed it through components using

<ViewClient works={works} />

This is how I just set the initial values.

const initialValues = {

   ...works
}

It works but when it comes to dates it just crashes/error as it would receive a timestamp.

This is how I usually do it manually.

   const conf =     data5.works.Figure4.conforme.date.seconds
   const newconf = new Date(conf*1000)

   const initialValues = {
     name:props.name
      age:props.age
      date1:conf 

         }

Can anyone give me idea/guide on how to proceed?

Forgot to add that I am using a custom date component.

export default function DatePicker(props) {
const { label, name } = props
return (
    <>
        <FormLabel>{label}</FormLabel>
        <Field name={name} >
            {
                ({ form, field }) => {
                    const { setFieldValue } = form
                    const { value } = field
                    return (
                        <DateView
                            className="chakra-input css-1c6j008"
                            id={name}
                            {...field}
                            selected={value}
                            onChange={val => setFieldValue(name, val)}
                            // minDate={new Date()}
                            // dateFormat='dd/MM/yyyy'
                            isClearable
                            peekNextMonth
                            showMonthDropdown
                            showYearDropdown
                            dropdownMode="select"
                        />
                    )
                }
            }
        </Field>
        <ErrorMessaging name={name} />
    </>
)

}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

My recomendation is to combine moment with some of the Date obj methods:
https://momentjs.com/
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

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