unjsifyContextProp<T> function

Context<T>? unjsifyContextProp<T>(
  1. ReactContext? value
)

Returns value converted back into its Dart Context representation, or null if the value is null.

For use in JS component prop getters where the component expects a JS context, but accepting Dart contexts is more convenient to the consumer reading/writing the props.

Should be used alongside unjsifyContextProp.

Note that Dart contexts currently lose their reified types when jsified/unjsified if they have not been passed into jsifyContextProp before.

Implementation

Context<T>? unjsifyContextProp<T>(ReactContext? value) {
  if (value == null) return null;

  // Return the original Dart context is there is one, otherwise return a new context.
  // See _dartContextForJsContext comment for more info.
  final originalContext = _dartContextForJsContext.get(value);
  return originalContext != null
      ? originalContext as Context<T>
      : Context<T>.fromJsContext(value);
}