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

162
Visualizações
Firebase fetching + React: Images won't load and getting a 500 error, but if I keep refreshing they show up

So I'm currently brushing up my react skills and learning firebase. I found it simple enough to configure and now I have been successfully making fetch requests from my realtime database.

I am currently building some sort of a birthday app that would show monthly and daily celebrants, and have generated mock data that I imported into my database. Currently, the first names are being fetched successfully and displaying on the screen, however the images (that are hosted on another site and fetched as a string from the db) are not loading properly and I'm getting 500 error in my console. If I keep refreshing though, they eventually load.

I'm thinking it must be with the way I make my fetch request. I basically fetch all users and then make a filter (have not explored fetching with queries yet) so I thought it would work.

This is the code for the fetch requests.

export const getUsers = () => {
    const usersDb = ref(database);
    return get(child(usersDb, `/users`)).then((snapshot) => {
        return snapshot.val();
    });
};


export const getMonthlyCelebrants = async () => {
    const users = await getUsers();
    const monthlyCelebs = [];
    for (let user in users) {
        const userMonth = +users[user]["birth_date"].split("/")[1];
        userMonth === getMonthNum() && monthlyCelebs.push(users[user]);
    }
    return monthlyCelebs;
};

And this is the Monthly Celebrants component I use them in:

export default function Monthly() {
  const [monthlyCelebs, setMonthlyCelebs] = useState([]);
  const [isLoading, setIsLoading] = useState(true);

  useEffect(() => {
    async function loadPage() {
      setIsLoading(true);
      const users = await getMonthlyCelebrants();
      setIsLoading(false);
      setMonthlyCelebs(users);
    }
    loadPage();
  }, []);

  return (
    <div>
      <h2>{getMonthAndYear()} Celebrants</h2>
      {isLoading ? (
        <p>Celebrants loading...</p>
      ) : (
        sortBirthdays(monthlyCelebs).map((monthlyCeleb) => {
          return (
            <SingleMonthlyCelebrant
              monthlyCeleb={monthlyCeleb}
              key={`${monthlyCeleb.birth_date}${monthlyCeleb.first_name}`}
            />
          );
        })
      )}
    </div>
  );
}

Any tips or advice would be greatly appreciated. Thank you!

about 4 years ago · Juan Pablo Isaza
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