jsifyMapProp function

JsMap? jsifyMapProp(
  1. Map? value
)

Returns a JS-deep-converted version of value for storage in the props map, or null if value is null.

For use in JS component prop setters where the component expects a JS object, but typing the getter/setter as a Dart Map is more convenient to the consumer reading/writing the props.

Should be used alongside unjsifyMapProp.

For more information on why this conversion is done in the getter/setter, see documentation around Dart wrapper component prop conversion issues. FIXME CPLAT-15060 add reference/link to documentation

Implementation

JsMap? jsifyMapProp(Map? value) {
  if (value == null) return null;
  // Use generateJsProps so that, in addition to deeply converting props, we also properly convert the `ref` prop.
  // Dart props get deep converted (just like they would when invoking the ReactJsComponentFactoryProxy anyways),
  // but that's a tradeoff we're willing to make, given that there's no perfect solution,
  // and shouldn't happen often since we shouldn't be passing Dart values to JS components.
  // As a workaround, consumers can wrap any Dart values in an opaque Dart object (similar to DartValueWrapper).
  return generateJsProps(value);
}