react-native - TypeError:试图分配给只读属性。在 Expo / GraphQL Apollo 客户端上
问题描述
我遇到了 TypeError: Attempted to assign to readonly 属性。这是在带有 Apollo 客户端的 Expo / React Native 上。
我有以下 GraphQL 查询
const GET_VIDEOS = gql`
{
users(limit: 3) {
userVideos {
muxPlaybackId
videoQuestion {
questionText
}
}
}
}
`;
我创建了以下组件:
export const VideoData = (ref) => {
const { data, error, loading } = useQuery(GET_VIDEOS);
if (loading) return null;
if (error) return `Error!: ${error}`;
console.log(data);
return (<Video
ref={ref}
source={{ uri: data.users[0].userVideos[0].muxPlaybackId}}
rate={1.0}
volume={1.0}
isMuted={false}
resizeMode="cover"
usePoster={true}
shouldPlay
isLooping
style={{ width: '100%', height: '100%'}}
>
</Video>
);
}
似乎问题来自以下行:
source={{ uri: data.users[0].userVideos[0].muxPlaybackId}}
但是我还能如何访问这个 muxPlaybackId 字符串?这是我需要的视频源的唯一值。
为了完整起见,这是我的 GraphQL 结果:
{
"data": {
"users": [
{
"userVideos": [
{
"muxPlaybackId": "e6ZNh139bm2Poz5xoPl4V4016fnRCPWcZbkrTxg3Ocys",
"videoQuestion": {
"questionText": "What do you miss most about normal life?"
}
},
{
"muxPlaybackId": "DeygMKplfbg4Ye6PtCiFDgMFI01AEBp1tnfoVD9k401Ws",
"videoQuestion": {
"questionText": "What is your favorite color?"
}
}
]
},
{
"userVideos": []
},
{
"userVideos": []
}
]
}
解决方案
我认为这个问题与您访问muxPlaybackId
. 运行时似乎在抱怨分配某些东西,而不是访问.
但是,可以肯定的是,不要使用表达式来访问 ,而是muxPlaybackId
尝试对其进行硬编码,看看是否有同样的问题:
source={{ uri: "e6ZNh139bm2Poz5xoPl4V4016fnRCPWcZbkrTxg3Ocys" }}
如果这仍然产生错误,那么我会查看Video
组件并查看允许设置哪些属性。
推荐阅读
- sql - 从开始和结束字符相同的字符串中检索文本
- java - 如何从对象列表中获取指定字段值最大的元素
- vue.js - 如何在 vue-cli 中使用`localIdentName`
- javascript - Angular 2 中无法识别自定义指令
- java - Setter 和 Getter
- vba - 如何根据来自另一个单元格范围的输入对二维单元格范围进行编号?
- angular - 角度请求中的Spring Boot安全403状态码
- powershell - 如何在单击时更改powershell中列表框的颜色?
- netsuite - 如何使用suitescript 2.0在文件柜中创建子文件夹
- javascript - 如果 requestIdleCallback 的回调执行时间过长而无法在空闲期间完成会怎样?