網(wǎng)站首頁 編程語言 正文
react props數(shù)據(jù)更改傳到方法里進(jìn)行渲染html,當(dāng)父組件改變props改變傳入函數(shù)參數(shù)沒有改變
作者:有問題請?jiān)u論我改 更新時(shí)間: 2022-04-05 編程語言解決方法使用JSON.parse(JSON.stringify(variableObject))深拷貝一下需變動的數(shù)組,因?yàn)槿绻豢截恗ap改變了數(shù)組(數(shù)組里的元素為引用類型),而react禁止改變props
getOnlineData = (roommates, onlineRoommates) => {
const newRoommates =JSON.parse(JSON.stringify(roommates))
return (newRoommates.map(item => {
onlineRoommates.map(element => {
if (`${item.user_type}:${item.user_id}` === element.userId) {
item.isOnline = true
item.hasVideo = element.hasVideo
item.hasAudio = element.hasAudio
}
})
return this.renderItem(item)
}))
}
render () {
const { roommates, onlineRoommates } = this.props
return (
<div className={styles.container}>
{this.getOnlineData(roommates, onlineRoommates)}
</div>
)
}
原文鏈接:https://blog.csdn.net/qq_26889291/article/details/122825536
相關(guān)推薦
- 2022-07-03 C#入門之定義類成員與接口實(shí)現(xiàn)_C#教程
- 2022-08-18 python打印日志方法的使用教程(logging模塊)_python
- 2023-01-31 Python函數(shù)用法和底層原理分析_python
- 2022-04-10 Mybatis if, set, where 動態(tài)sql和sql片段的使用
- 2022-09-18 centos+nginx+uwsgi部署django項(xiàng)目上線_python
- 2022-12-10 Input系統(tǒng)之InputReader概要性實(shí)例分析_Android
- 2022-12-23 一文帶你了解Android中的網(wǎng)絡(luò)請求_Android
- 2023-01-09 Pyscript使用本地Pyodide配置步驟_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支