react-native 报错:In this environment the target of assign MUST be an object.This error is a performa

知识点: StyleSheet.create :Creates a StyleSheet style reference from the given object. 样式来自样式表的引用。接收一个obj,返回的不是一个obj
 

所以直接使用...或Object.assign()会报错。解决方法有如下2种:

1.StyleSheet.flatten 返回一个obj,可以用StyleSheet.flatten 包装成对象,再使用...或Object.assign()

react-native 报错:In this environment the target of assign MUST be an object.This error is a performa

<View style={{ ...StyleSheet.flatten(styles.statusWrap), backgroundColor: statusObj.bgColor }}></View>

2. 使用官网的例子:https://facebook.github.io/react-native/docs/stylesheet.html#content 

react-native 报错:In this environment the target of assign MUST be an object.This error is a performa

<View style={[styles.statusWrap, { backgroundColor: statusObj.bgColor }]}></View>