【发布时间】:2021-09-28 22:54:38
【问题描述】:
我正在从我的数据库中读取文档,其中包含非规范化数据。我使用这些数据来呈现一个可点击的 GUI 组件“UserListItem”。
当用户按下此组件时,它将导航到屏幕“配置文件”。
因此,例如,如果在获取非规范化文档后,我会得到以下信息:
{
userData: { // Denormalized data
id,
avatar,
name,
username,
isCelebrity
},
... other stuff
}
用户点击时导航到的“个人资料”屏幕需要以下用户字段:
userData = {
/* Included in denormalization */
id,
avatar,
name,
username,
isCelebrity,
/* Not included in denormalization */
totalFollowers,
totalFollowing,
status,
premium,
}
我该如何处理这种情况?我的意思是,典型的策略是什么?
我曾考虑在个人资料屏幕中执行此操作:
useEffect(() => {
if(!isUserDataComplete(userData)) { // Check that the userData object contains all the required fields
const newUserData = getUserData(userData.id); // DB Fetch
users.updateData(newUserData); // Updating the user data in our context
}
}, []);
但不确定这是否是一个好的和“干净”的方法。
还有,这种情况有名字吗?阅读更多相关信息。
【问题讨论】:
标签: javascript reactjs firebase nosql denormalization