unconvertJsProps function
Returns the props for a ReactElement or composite ReactComponent instance
,
shallow-converted to a Dart Map for convenience.
If style
is specified in props, then it too is shallow-converted and included
in the returned Map.
Implementation
Map unconvertJsProps(/* ReactElement|ReactComponent */ instance) {
final props = Map.from(JsBackedMap.backedBy(instance.props as JsMap));
// Catch if a Dart component has been passed in. Component (version 1) can be identified by having the "internal"
// prop. Component2, however, does not have that but can be detected by checking whether or not the style prop is a
// Map. Because non-Dart components will have a JS Object, it can be assumed that if the style prop is a Map then
// it is a Dart Component.
// ignore: deprecated_member_use_from_same_package
if (props['internal'] is ReactDartComponentInternal || (props['style'] != null && props['style'] is Map)) {
throw ArgumentError('A Dart Component cannot be passed into unconvertJsProps.');
}
// Convert the nested style map so it can be read by Dart code.
final style = props['style'];
if (style != null) {
props['style'] = Map<String, dynamic>.from(JsBackedMap.backedBy(style as JsMap));
}
return props;
}