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

441
Visualizações
Why is the data that I'm getting from axios not working but when I use the same data in a const it works normally

I'm getting data from axios by using axios.get and saving the data in a state, and then trying to use that data in a component's prop named disabledDates so i insert the state in the prop and nothing happens but when i put the same data in a const it works

const [selected, setSelected] = useState("");

const url = "http://000.000.0.00:0000/calendar";

const [data, setData] = useState("");

useEffect(() => {
    // Update the document title using the browser API
    axios
        .get(url)
        .then((res) => setData(JSON.stringify(res.data[0].date)))
        .catch((err) => {
            console.error(err);
        });
}, [data]);

console.log(data);

return (
    <SafeAreaView style={styles.container}>
        <CalendarPicker
            onDateChange={(date) => setSelected(date)}
            disabledDates={data}
            disabledDatesTextStyle={{ color: "red" }}
        />
    </SafeAreaView>
);

this is the code that contains the issue

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I see two things wrong with your react code.

  1. your use of useEffect is incorrect.

You have dataa as a dependency. Every time your axios request finishes and it sets the data on the state, dataa will change and you will remake the request going into an infinite loop.

  1. You use JSON.stringify() to convert a Json response to a string.

I am not aware which specific library you are using for the date picker but it is unlikely that it expects a string.

Axios responses are already a JavaScript object so just set that to the state of your component, no need to stringify. This will depend on the documentation of the library you are using and in which format they expect the data.

over 4 years ago · Santiago Trujillo 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