An implementation for a custom renderer for React
In order to create a custom renderer, you have to define a HostConfig, see the HostConfig Interface below.
For your references, these are HostConfigs of custom renderers
- react-dom
- react-native
- react-test-renderer
- react-konva
Return a public instance of Host component.
react-dom
returns a DOM element because it is a public instance that you can get through ref
.
getChildHostContext(parentHostContext: HostContext, type: Type, rootContainerInstance: Container): HostContext
createInstance(type: Type, props: Props, rootContainerInstance: Container, hostContext: HostContext, internalInstanceHandle: OpaqueHandle): Instance;
Return an instance.
react-dom
returns a DOM element.
Append an instance into a parent instance.
react-dom
calls parentInstance.appendChild(child)
.
This is called in the render phase but it's ok because a DOM tree hasn't been mounted yet.
finalizeInitialChildren(parentInstance: Instance, type: Type, props: Props, rootContainerInstance: Container, hostContext: HostContext): boolean;
Set initial properties and return whether commitMount
should be called in later or not.
react-dom
set DOM properties and return a boolean that indicates whether dom.focus()
should be called in commitMount
or not.
prepareUpdate(instance: Instance, type: Type, oldProps: Props, newProps: Props, rootContainerInstance: Container, hostContext: HostContext): null | UpdatePayload;
Return updatePayload
includes properties for diffs
react-dom
returns a props list has to be applied.
Return whether its content is a textContext or not.
Return whether updating its subtree is deprioritized or not.
react-dom
return a flag whether hidden
prop is true
or not.
createTextInstance(text: string, rootContainerInstance: Container, hostContext: HostContext, internalInstanceHandle: OpaqueHandle): TextInstance;
Return an text instance.
react-dom
return a textNode.
// Temporary workaround for scenario where multiple renderers concurrently
// render using the same context objects. E.g. React DOM and React ART on the
// same page. DOM is the primary renderer; ART is the secondary renderer.