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

195
Visualizações
show array data in react table

I have an both an array, and the state array.

 const [formData, setFormData] = useState([]);
  let ure = [{}]
  
  useEffect(() => {
    axios
      .get("/api/listUre")
      .then((res) => {
        console.log(res.data)
        //setFormData(res.data);
       ure.push({
             class_id: res.data.class_id
         })
      })
      .catch((error) => {
        // Handle the errors here
        console.log(error);
      })
      .finally(() => {
      });
  }, []);

once I do that, I now want to access the class_id from within a table:

{ure.length > 0 &&
            ure.map((obj, index) => {

       
          <tr key={index}>
            <td>
              {obj.class_id}
            </td>
            <td>
              {obj.class_id}
            </td>
            <td>
               My Name
            </td>
          </tr>
         })}
      {ure.length === 0 && "No Data Found"}

I am not sure what I am doing wrong, but it is not outputting anything to the page. and i know that the ure array has data in it because it isn't outputting "No Data Found" to the screen, so it should be working. can anyone help me out?

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

0

I think you need ure to be a piece of state, otherwise your ure array will keep getting reevaluated each time your component re-renders.

So, the first step would be to:

const [ure, setUre] = useState([]);

Then for changing ure, just do something like:

setUre(currUre => {
  return currUre.concat([{ foo: bar }]);
})

Then, to iterate over it, you shouldn't need to check the length > 0, just the map() will do the trick.

The reason why you're seeing that outcome (no table but no empty array) is because you're initializing let ure = [{}], which is an array of size 1 with an empty object in it.

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