第 4 步:关注状态切换
本课属于 Coddy React 学习旅程的“基础知识”单元。第 42 课,共 42 课。
挑战
中等完成个人资料卡。
- 为
ProfileCard添加布尔状态following(初始值为false)。 - 添加一个
id="follow"的按钮,点击时切换该状态。 - 状态为 true 时,按钮标签为
Following;状态为 false 时,按钮标签为Follow。
亲手试试
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div id="root"></div>
<script type="module" src="main.jsx"></script>
</body>
</html>