美文网首页程序员
In this environment the target o

In this environment the target o

作者: JsLin_ | 来源:发表于2018-10-12 23:24 被阅读8次

封装组件的时候,碰到这个问题,看起来写法也没问题
但是就是红屏报错

  this.setState({
        style:
        {
          ...this.props.defalutStyle,
          left: _previousLeft,
          top: _previousTop,
        }
      });

In this environment the target of assign MUST be an object.This error is a performance optimization

大概意思是 :环境中必须使用对象
莫名其妙,最后查下,有人和我遇到同样的问题 同样错误
这个大佬说了下:

image.png

官网例子:(这个算比较冷的知识) 传送门

下面就改下代码,用的时候正常传


image.png

我们在组件层改下:

 this.setState({
        style:
        {
          ...StyleSheet.flatten(defalutStyle),
          left: _previousLeft,
          top: _previousTop,
        }
      });

导致这个问题的原因可能是StyleSheet.create 下的对象 返回的不是一个object,官网也说了 StyleSheet.create :Creates a StyleSheet style reference from the given object. 样式来自样式表的引用。接收一个obj,返回的不是一个obj
StyleSheet.flatten 返回一个obj

相关文章

网友评论

    本文标题:In this environment the target o

    本文链接:https://www.haomeiwen.com/subject/mcenaftx.html