我这里有我的代码,可以得到btc的价格。
function Nft() {
const[price,setPrice]=useState(0);
setTimeout(() => {
fetch('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd')
.then((res)=>res.json())
.then((response)=>{
//your response is like
试图在useState内部setInterval of a preact/hook。这是不起作用的,看起来永远都是迭代,它正在执行以前的回调堆栈(?)。有人能帮我理解和修复这个片段吗?
import {h} from 'preact';
import {useState} from 'preact/hooks'
const interests = [
{name: 'the future',},
{name: 'architecture',},
{name: 'my work',},
{name:
我刚接触React和JS,遇到了一个问题。我想显示一个模态后,用户已经在网站上5秒。我正在尝试使用"setTimeout“函数来延迟我的模式的渲染。我不知道为什么这不起作用。任何帮助都是非常感谢的。提前感谢!! import styled from 'styled-components'
import Team from '../../images/Team.svg'
import { Button, Background, ModalWrapper, ModalImg, ModalContent, CloseModalButton } from &
我有一个简单的功能组件,在这里我点击一个按钮并显示出来,当单击按钮时,我尝试让导入的旋转器显示2秒,然后在两秒钟后显示导入的组件,但是,我只能在单击按钮后使旋转器显示2秒,并且无法使它停止。
import React, { useState } from "react";
import Hello from "./Hello";
import Spinner from '../Spinner/Spinner'
import "./styles.css";
export default function App() {
con