reactjs – Basic react question – click dont display Data
I am trying to learn react and creating application First time. I have created basic application where just displaying two link on page with home and view. when click on view it will read data from file (data.json) and try to load data on the page and display . I can see data in console log but dont know why its not displaying on page. Also seems like my application routing isnt perfect.
Please help me understand or guide me how I can make it correct.
App.js
function App() {
return (
);
}
export default App;
View.js
import React, { useState, useEffect } from 'react';
export function View(){
const [data, setData] = useState([]);
useEffect(() => {
fetch("/data.json")
.then((res) => {
console.log(`got response ${res}`);
return res.json();
}).then((data) => {
console.log(`data : ${JSON.stringify(data)}`);
if (Array.isArray(data)) {
setData(data);
} else {
// Do something to transform it to an array
}
});
}, []);
return (
);
}
Menulink.js
export function Menulink() {
return (
} />
} />
);
}
Home.js
export function Home() {
return (
Welcome to the home page!
);
}
when i click on view it dont display data. Please help me understand what is wrong in code. i am creating application first time.
Thank you
Read more here: Source link
