Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用反应钩子 useEffect 来获取建议 api。每次刷新页面后它都会自动更改我如何使用按钮事件自动更改
您需要创建一个函数来获取您的数据,例如
const fetchData=()=>{ //API call }
并向您的按钮添加一个调用 api 并使用 setState 更新它的事件。
<button onClick={()=>{ let data=fetchData(); setQuote(data); }}> </button>