非常感谢您的帮助,我在React中构建了一个简单的引用生成器项目,并希望在不渲染整个页面的情况下加载新引用。目前,我正在使用hooks并且引用状态位于一个组件中,是否可能通过点击处理程序从另一个组件重新加载/刷新状态?
项目链接:https://codesandbox.io/s/quote-generator-czffn?file=/src/components/buttons/Buttons.js 目前是如何重新加载的,使用refreshPage函数。谢谢!
项目链接:https://codesandbox.io/s/quote-generator-czffn?file=/src/components/buttons/Buttons.js 目前是如何重新加载的,使用refreshPage函数。谢谢!
import React from 'react';
const Buttons = ({ quotes, getNewQuote }) => {
const twitterUrl = `https://twitter.com/intent/tweet?text=${quotes.joke}`;
// console.log(twitterUrl);
function refreshPage() {
window.location.reload(false);
}
return (
<div className='button-container'>
<button
onClick={() => window.open(twitterUrl, '_blank')}
className='twitter-button'
id='twitter'
tittle='Tweet This!'
>
<i className='fab fa-twitter'></i>
</button>
<button id='new-quote' onClick={refreshPage}>
New Quote
</button>
</div>
);
};
export default Buttons;