我正在使用react聊天小工具,在这个小工具中,我能够获得我在徽章中收到的新消息的计数,但我想在单击隐藏按钮后清除批量值
export default class App extends React.Component
{
constructor(props)
{
state = {
count:0
}
}
}
用于递增该值
this.setState((old_state)=>{
let new_count = ++old_state.count;
return { count: new_count }
})
内部呈现函数badge={this.state.count}
launcher组件如下所示
const Launcher = ({ toggle, chatOpened, badge, bgcolor }) =>
<button type="button" style={{backgroundColor : bgcolor}} className={chatOpened ? 'rcw-launcher rcw-hide-sm' : 'rcw-launcher'} onClick={toggle}>
{chatOpened ?
<img src={close} className="rcw-close-launcher" alt="" />:
<React.Fragment><Badge badge={badge} /><img src={openLauncher} className="rcw-open-launcher" alt="" /></React.Fragment>
}
</button>;
我不能理解在读完一次消息后如何更改值。
发布于 2020-01-24 15:59:11
当chatOpened为true时,将状态计数设置为0。或将0传递给徽章计数;
https://stackoverflow.com/questions/59892427
复制相似问题