Skip to content

DOM Node APIs#844

Draft
Freddy03h wants to merge 2 commits intomainfrom
dom-node-api
Draft

DOM Node APIs#844
Freddy03h wants to merge 2 commits intomainfrom
dom-node-api

Conversation

@Freddy03h
Copy link
Member

Blog Post : Starting from React Native 0.82, native components will provide DOM-like nodes via refs.
Documentation : Nodes from refs


I tried to follow the approach used in experimental-rescript-webapi but I hope this rescript feature for tagged variants can be addressed soon, as it would provide a better DX.

In the meantime, I added a NodeTypeHelper module to help with type conversions.
I know it doesn’t follow the zero-runtime binding rule, but while experimenting with experimental-rescript-webapi, I found this kind of helper quite useful, and it would otherwise have to be reimplemented in every project.

@Freddy03h
Copy link
Member Author

Freddy03h commented Mar 10, 2026

Migration should be easy if the rescript feature for tagged variants is accepted.

Example with the current PR

let textData = switch element.childNodes
->DOMApi.NodeList.item(0)
->Null.map(node => node->DOMApi.NodeTypeHelper.findNodeType) {
| Null.Value(Text(text)) => text.data
| _ => "not a text node"
}

Example with the rescript feature for tagged variants.

let textData = switch element.childNodes->DOMApi.NodeList.item(0) {
| Null.Value(Text(text)) => text.data
| _ => "not a text node"
}

@fhammerschmidt fhammerschmidt requested a review from cknitt March 12, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant