nextjs-mysql-tutorial's People
Forkers
pedropankaj luqmaanbelim clipartinc godcomplexxx mksuni forengineer-hub riflemanim dodicandra samitakinextjs-mysql-tutorial's Issues
TypeError: can't access property "map", dataResponse is undefined
I followed the youtube video and compared the code again here on youtuber. Unfortunately I keep getting this error and I don't know what I did wrong.
my [name].js
`import { useEffect, useState } from "react";
import { useRouter } from "next/router";
export default function Statistics() {
const router = useRouter();
const {playername} = router.query;
const [dataResponse, setdataResponse] = useState([]);
useEffect(() => {
if (!router.isReady) return;
async function getPlayerData() {
const apiUrlEndpoint = http://localhost:3000/api/getdata-lib-router
;
const postData = {
method: "Post",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
playername: playername,
}),
};
const response = await fetch(apiUrlEndpoint, postData);
const res = await response.json();
setdataResponse(res.levels);
}
getPlayerData();
}, [router.query.playername, router.isReady]);
useEffect(() => {
console.log(dataResponse)
}, [dataResponse])
return(
<>
<div>
{/* {dataResponse.map((levels) => {
return(
<div>
<p>{levels.playername}</p>
<p>{levels.playerlevel}</p>
<br />
</div>
)
})} */}
{dataResponse.map((levels) => {
return (
<div key={levels.playeruuid}>
<div>{levels.playername}</div>
</div>
);
})}
</div>
</>
)
}`
my getdata-lib-router.js
`import { query } from "../../lib/db";
export default async function handler(req, res) {
const playername = req.body.playername;
try {
const querySql =
"SELECT * FROM levels WHERE playername = ?";
const valueParams = [playername];
const data = await query({ query: querySql, values: valueParams });
res.status(200).json({ levels: data });
} catch (error) {
// unhide to check error
res.status(500).json({ error: error.message });
}
}
//if needed
// export const config = {
// api: {
// externalResolver: true,
// },
// };`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.