gpt4 book ai didi

javascript - 在 ReactJS 中切换类

转载 作者:行者123 更新时间:2023-11-29 21:42:41 24 4
gpt4 key购买 nike

我试图在单击“关注”按钮时将类名切换为“事件”。我尝试按照 React 网站上的教程和指南以及其他引用资料进行操作,但没有成功。下面是我的代码:

import React from 'react';
import styles from './Cover.css';
import withStyles from '../../decorators/withStyles';
import Link from '../../utils/Link';
import Avatar from './Avatar';

import { Button } from 'react-bootstrap';

@withStyles(styles)
class Cover extends React.Component {


render() {
return (
<div className="Cover">
<div className="Cover-container">
<div>
<Avatar
username="hilarl"
profession="Web Developer"
location="New York, New York"
status="I am here to protect my business, a bunch of kids are out to ruin me" />
<div className="Cover-submenu-container">
<div className="Cover-submenu-section">
.
</div>
<div className="Cover-submenu-section links">
<a href="#" className="Cover-submenu-link">
<i className="fa fa-twitter"></i>
</a>
<a href="#" className="Cover-submenu-link">
<i className="fa fa-facebook"></i>
</a>
</div>

// follow button

<div className="Cover-submenu-section connect-menu">
<Button className="follow-btn" href="#">Follow</Button>
</div>
</div>
</div>
</div>
</div>
);
}
}

export default Cover;

如果有人能帮忙解决这个问题就太好了。谢谢

最佳答案

您使用事件类渲染 Button。

render () {
let isFollowing = this.state.isFollowing
...
<Button className={`follow-btn ${isFollowing? ' active':''}`} ...

您现在需要做的就是在单击按钮时更新 isFollowing。

关于javascript - 在 ReactJS 中切换类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32224411/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com