Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
Por qué mi pantalla se vuelve blanca al llamar a la API por primera vez pero funciona la segunda vez

Como mencioné en el título, mi pantalla se vuelve blanca al llamar a la API por primera vez, pero cuando actualizo e ingreso el valor, funciona correctamente.

en la consola, el error es: TypeError no detectado: Value.map no es una función

 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 answers
Answer question

0

Porque el estado inicial de Value es una cadena vacía. No hay nada allí, así que no hay nada que mapear. Cuando usa setValue después de escribir la entrada, su estado se actualiza para reflejar lo que haya escrito, por lo que solo entonces puede mapear Value .

about 4 years ago · Juan Pablo Isaza Report

0

Debe verificar si hay Value , agregar Value && así:

 {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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!