当前位置:网站首页>The left-hand side of an assignment expression may not be an optional property access. ts(2779)

The left-hand side of an assignment expression may not be an optional property access. ts(2779)

2022-07-07 12:28:00 Zh afai

background

Write ts and react ref when There are the following errors
 Insert picture description here
It means iframeRef.current May is empty , We cannot assign values directly like this , Then we just tell the editor iframeRef.current It is OK to assign a value again

solve

  • Use !., This is just ts Type inference of , When running iframeRef.curent If there is no value, it will still be thrown wrong
     Insert picture description here
  • Use condition judgment - recommend
     Insert picture description here
原网站

版权声明
本文为[Zh afai]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071024579672.html