reactjs - 有没有办法根据 id 更改单击的按钮的文本
问题描述
const [toFollow, setToFollow] = useState('follow')
const follow = (user_id) => {
users && users.map(user => {
if(user.user_id !== user_id){
setToFollow('following')
}
})
}
这是数组。问题是当我只想要点击更改的 id 时,整个跟随道具都会发生变化
<FlatList
style={{marginBottom: 60}}
showsVerticalScrollIndicator = {false}
data={users && users}
renderItem={({ item }) => (
<UserFollowCard
p_image={item.profile_image}
name={item.name_of_user}
username={item.username}
textToFollow={toFollow}
follow = {() => follow(item.user_id)}
/>
)}
keyExtractor={item => item.user_id}
/>
t
this is the flatlist rendering the array with the component
解决方案
我对这个问题不是很清楚。您可以根据条件更改按钮标题。我写了一些代码,这里是链接。您可以使用 TouchableOpacity 代替 Button。
推荐阅读
- reactjs - 无法在 ReactJS 中获取本地 IP 地址
- flutter - Flutter:异常:类型'(动态,动态,动态)=> void'不是'f'类型'(字符串,动态)=> void'的子类型
- docker - GitHub Packages Docker - 提取图像配置时出错:未知 blob
- java - 适配器模式应用
- sql - SQL 检查订单日期的更改频率
- sql - 如何在Oracle中知道带有照片的表的大小
- ios - 更改控制中心的可访问性标签(远程命令中心)
- ios - 如何使用 Swift 5 从 iOS13 的后台应用程序中获取活动应用程序的名称?
- reactjs - ReactJS - 无需更改多个组件之间的 URL 切换
- ruby-on-rails - rails 6 app 测试为绿色,但在生产中出现奇怪的效果:LoadError(无法加载此类文件——rb-readline)