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

103
Visualizações
Why my screen goes white on calling API for first time but it works on second time

As I mentioned in title my screen goes white on calling API for first time but when I refresh and inputs the value it works properly

on console the error is : Uncaught TypeError: Value.map is not a function

  const [data, setData] = useState({});
  const [user, setUser] = useState("");
  const [Value, setValue] = useState("");

  const APIurl = async () => {await axios.get(`https://api.github.com/users/${user}`).then((response) => { setData(response.data);
      console.log(response.data); });};

  const APIurl1 = () => {
    axios.get(`https://api.github.com/users/${user}` + `/repos`).then((response) => {
        setValue(response.data);
        console.log(response.data);
      }); };

  const handleKey = (e) => {
    if (e.key === "Enter") {
      APIurl();APIurl1();}};

  return (
    <>
      <div className="bbody">
        <input
          id="search-bar"
          onChange={(event) => setUser(event.target.value)}
          placeholder="Enter User"
          type="text"
          onKeyPress={handleKey}
        />

        {!data.name ? (
          <div>
            <p className="errorMsg">No Data Found</p>
          </div>
        ) : (
          <>
                <div className="inner-img">
                  <img src={data.avatar_url} alt="" />          
                  <h2>{data.name}</h2>
                  <p>{data.bio}</p>
                  <div id="repos">
                    {Value.map((value) => {
                      return (
                        <a key={value.id} href={value.html_url} target="_blank">
                          <button id="repos-link">{value.name}</button>
                        </a>
                      );
                    })}
                 ```

I m trying to get Github profile of a person by inputting name in the input field and extracting the info from the API.


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

0

Because the initial state of Value is an empty string. Nothing is there, so there's nothing to map. When you use setValue after typing in the input its state is updated to reflect whatever you've typed, so only then can you map over Value.

about 4 years ago · Juan Pablo Isaza Relatório

0

You should check if there is Value, add Value && like so:

 {Value &&
   Value?.map((value) => {
     return (
       <a key={value.id} href={value.html_url} target="_blank">
         <button id="repos-link">{value.name}</button>
        </a>
      );
  })}
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