0
# Core Utilities
1
2
Essential utilities for rendering, element creation, and DOM integration. These provide the foundation for React Native Web's compatibility layer.
3
4
## Rendering
5
6
### render
7
8
Renders a React Native Web application to a DOM container. This is the primary entry point for web applications.
9
10
```javascript { .api }
11
function render(
12
element: React.Element,
13
container: DOMContainer,
14
callback?: Function
15
): void;
16
```
17
18
**Parameters:**
19
- `element` - The React element to render
20
- `container` - DOM element to render into
21
- `callback` - Optional callback called after render
22
23
**Usage:**
24
```javascript
25
import { AppRegistry } from "react-native-web";
26
27
AppRegistry.registerComponent("App", () => App);
28
AppRegistry.runApplication("App", {
29
rootTag: document.getElementById("root"),
30
});
31
```
32
33
### unmountComponentAtNode
34
35
Unmounts a React Native Web component from a DOM container.
36
37
```javascript { .api }
38
function unmountComponentAtNode(container: DOMContainer): boolean;
39
```
40
41
**Parameters:**
42
- `container` - DOM container to unmount from
43
44
**Returns:** `boolean` - true if component was unmounted
45
46
## DOM Integration
47
48
### findNodeHandle
49
50
Returns the DOM node handle for a React Native component reference. Used for measuring and DOM operations.
51
52
```javascript { .api }
53
function findNodeHandle(componentOrHandle: any): number | null;
54
```
55
56
**Parameters:**
57
- `componentOrHandle` - React component reference or existing handle
58
59
**Returns:** `number | null` - DOM node handle or null
60
61
**Usage:**
62
```javascript
63
const viewRef = useRef();
64
const nodeHandle = findNodeHandle(viewRef.current);
65
```
66
67
### unstable_createElement
68
69
Low-level element creation utility with React Native compatibility. Handles style, event, and prop normalization for web.
70
71
```javascript { .api }
72
function unstable_createElement(
73
type: string,
74
props?: Object,
75
...children: any[]
76
): React.Element;
77
```
78
79
**Parameters:**
80
- `type` - Element type (string or component)
81
- `props` - Element properties
82
- `children` - Child elements
83
84
**Returns:** `React.Element` - Created React element
85
86
*Note: This is an unstable API and may change in future versions.*
87
88
## Color Processing
89
90
### processColor
91
92
Processes and normalizes color values to web-compatible formats. Handles React Native color formats and converts them for web use.
93
94
```javascript { .api }
95
function processColor(color: ColorValue): string | null;
96
```
97
98
**Parameters:**
99
- `color` - Color value (string, number, or null)
100
101
**Returns:** `string | null` - Processed CSS color string or null
102
103
**Usage:**
104
```javascript
105
const webColor = processColor('#FF0000'); // Returns '#FF0000'
106
const webColor2 = processColor('red'); // Returns 'red'
107
const webColor3 = processColor(0xFF0000); // Returns '#ff0000'
108
```
109
110
## Native Modules
111
112
### NativeModules
113
114
Empty object for React Native compatibility. Maintains API compatibility with React Native but contains no modules on web.
115
116
```javascript { .api }
117
const NativeModules: {};
118
```
119
120
This is provided for compatibility with React Native code that may reference `NativeModules`, but will be empty on web platforms.