Sep 1 (edited) in Help
VSC next.js question. No console log but the hook happens
edit: I figured it out but leaving the question up anyway.
Below is some code I have for the crypto app. Nothing special. I'm just playing around for now to get used to it. I'm getting the bitcoin data here for now.
When I fire up "npm run dev" everything happens like it should. The console prints "made it" so I know it's at least firing the getData function. However anytime I try and click the button to console log "test" nothing prints but the "up" hook does increment. So I know the function is getting called.
Why does it not console log in my handleClick method but it does call the hook?
"use client";
import { useState } from "react";
import {
Title, MainWrapper, GraphWrapper, CoinHeaderWrapper, CoinStatsWrapper, } from "./styles";
export default function Home() {
const [up, setUp] = useState(0);
async function getData() {
let data = await fetch(
);
console.log("made it");
let bitCoinNumbers = await data.json();
}
const handleClick = () => {
setUp(up + 1);
console.log("test");
};
getData();
return (
...
<button className="bg-white" onClick={handleClick}> {up} </button>
...
);
}
3
6 comments
Bret Miller
6
VSC next.js question. No console log but the hook happens
Developer Pro
skool.com/developerpro
Learn how to code. Make money. Have fun. Enjoy life.
Leaderboard (30-day)
powered by