Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
Why specific URL not working in Json rest api react?

I am using codesandbox to fetch api with react hooks

While this below code working well ,

import "./styles.css";
import { useState, useEffect } from "react";
import ReactDOM from "react-dom/client";

export default function App() {
  const [data, setData] = useState(null);

  useEffect(() => {
    fetch("https://jsonplaceholder.typicode.com/todos")
      .then((res) => res.json())
      .then((data) => setData(data));
  }, []);
  return (
    <div className="App">
      <>
      {data &&
        data.map((item) => {
          return <p key={item.id}>{item.title}</p>;
        })}
    </>
    </div>
  );
}

Same code is not working just if I change URL which is below

import "./styles.css";
import { useState, useEffect } from "react";
import ReactDOM from "react-dom/client";

export default function App() {
  const [data, setData] = useState(null);

  useEffect(() => {
    fetch("https://www1.nseindia.com/homepage/Indices1.json")
      .then((res) => res.json())
      .then((data) => setData(data));
  }, []);
  return (
    <div className="App">
      <>
      {data &&
        data.map((item) => {
          return <p key={item.preClose}>{item.id}</p>;
        })}
    </>
    </div>
  );
}

and its throwing error

Type Error 

Failed to fetch

I am unable to identify issue over here

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda