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

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

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 Report

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 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!