在有状态组件中,我有以下代码:
const handleUserClick = (username, usermemo, userSelected) => {
const isUsername = userName === username ? "Select a user" : username;
const isUsermemo = userMemo === usermemo ? null : usermemo;
setUserName(isUsername);
setUserMemo(isUsermemo);
setSelectedUser(userSelected);
};
在无状态组件中,我有以下代码:
const selectUserClick = ({ target }) => {
let selectedUserIndex = USERS_DATA[target.value];
let username = `${selectedUserIndex.first_name} ${selectedUserIndex.last_name}
- ${selectedUserIndex.occupation}`;
let usermemo = `"${selectedUserIndex.catch_phrase}"`;
userSelected = target.classList.toggle("selected");
getUser(username, usermemo, userSelected);`enter code here`
};
斯蒂芬大帝
Qyouu
陪伴而非守候
相关分类