React Typescript 报错 Cannot assign to 'current' because it is a read-only property.

原创
2021/03/26 23:41
阅读数 7.9K

 

原文链接: React Typescript 报错 Cannot assign to 'current' because it is a read-only property.

上一篇: 修复: WebGL: INVALID_VALUE: tex(Sub)Image2D: video visible size is empty

下一篇: git 设置常用别名

用ts写的时候遇到一个报错, 有点离谱,但是原因比较简单...

第一次遇到, 排查花了一些时间...

Cannot assign to 'current' because it is a read-only property.

 

简单复现

import { useRef } from 'react';

export default () => {
  const countRef = useRef<number>(null);

  countRef.current = 1;
};

 

主要还是这个信息不明确, 让我怀疑到其他地方了

 

总的来说就是默认的初始值很重要!

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部