fix: allow patching of react.createElement #897
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
Analytics libraries like datadog patch
React.createElement
to override onPress prop for tracking. HereAlthough, not a huge fan of the approach taken here by the datadog library as alternate solutions exist. But I think
react-native-css-interop
should support such a usecase as the originalReact.createElement
doesn't prevent patching.Approach
RN CSS interop uses named import
createInteropElement
to replacecreateElement
, this prevents patching, as babel transpiles such imports to read-only. The approach taken in this PR is to use namespace imports. e.g.createElement
will becomeReactNativeCSSInterop.createInteropElement
. Such an import is not considered read-only and users can perform patchingReactNativeCSSInterop.createInteropElement = () => {}
Note
This PR is a partial solution to allow patching
React.createElement
. NativeWind's currenttsc
approach to build distribution packages generates below output. This output lacks ability to mutatecreateInteropElement
as it only has a getter inObject.define
, nowritable
. I think we should distribute packages withesnext
module preset in tsconfig or use expo module scripts for distribution builds. Would love to know your thoughts on this.