What is the point of StyleSheet.create

前端 未结 3 1992
旧时难觅i
旧时难觅i 2020-12-05 17:01

I\'m reading the React Native docs / tutorial, and I\'m wondering what the point of the StyleSheet.create function is.

For example, the tutorial has the

3条回答
  •  鱼传尺愫
    2020-12-05 17:27

    Here is there source code of create.

    create(obj: T): {[key:$Keys]: number} {
      var result: T = (({}: any): T);
      for (var key in obj) {
        StyleSheetValidation.validateStyle(key, obj);
        result[key] = ReactNativePropRegistry.register(obj[key]);
      }
      return result;
    }
    

    I am not an expert of React in any. I actually never used it but here are my insights. It seems that create does some kind of validation over your keys and register them to React.

    I think you could skip the validation by simply not calling create but I'm not sure what ReactNativePropRegistry.register does exactly.

    Reference to the source

提交回复
热议问题