теперь нет ошибок но значение data undfined
App.js
import React from "react";
import Shop from "./pages/Shop";
// client/src/App.js
function App({arrayse}) {
const [data, setData] = React.useState(null);
React.useEffect(() => {
const res= fetch('http://localhost:3001/api',{mode: 'no-cors'});
setData(res.json);
}, []);
console.log(data);
return (
<div className="App">
<header className="App-header">
<p>{!data ? "Loading..." : data}</p>
</header>
<Shop arrayse={arrayse}/>
</div>
)
}
export default App;
index.php
const express = require("express");
const PORT = 3001;
const app = express();
app.get("/api", (req, res) => {
res.set('Access-Control-Allow-Origin', 'https://localhost:3001',{mode: 'no-cors'});
res.json({ message: "Hello from server!" });
});
app.listen(PORT, () => {
console.log(`Server listening on ${PORT}`);
});