Skip to main content

Migrating to v6

important

V6 is a brand new rewrite of the library, bringing amazing new features such as whitespace collapsing, list style type support, and enhanced performances. However, it will take some work to migrate your project to support the new API.

Props#

note

A good amount of props have had their name changes, while their behavior is similar or equivalent. The biggest endeavor will be to migrate custom renderers.

Props to Monitor#

PropRemarks
renderersEach renderer function should be converted to a React Component. See Custom Rendering guide and the below section, Migrating Custom Renderers.
renderersPropsTo access those props from a custom renderer, you should now use useRendererProps hook.
sourceA new type of source is available, source.dom. See DOM Tampering for a use case.
computeEmbeddedMaxWidthYou can now take advantage of useComputeMaxWidthForTag hook to consume max width from custom renderers.
tagsStylesThose styles are now mixed styles records, which are unlikely to break. See Styling Components.
classesStylesThose styles are now mixed styles records, which are unlikely to break. See Styling Components.
allowedStylesCSS properties are now camelCased.
ignoredStylesCSS properties are now camelCased.

Renamed and Moved Props#

v5v6Remarks
enableExperimentalPercentWidthrenderersProps.img.enableExperimentalPercentWidth
imagesInitialDimensionsrenderersProps.img.initialDimensions
onLinkPressrenderersProps.a.onPress
onParsedonTTreeUpdateThe structure has changed. See Transient Render Engine.
listsPrefixesRendererscustomListStyleSpecsThe API has changed, see Lists, customization.
ignoredTagsignoredDomTags
ignoreNodesFunctionignoreDomNode

Discontinued Props#

PropRemarks
containerStyleYou can use baseStyle instead.
customWrapper
ptSize
baseFontStyleYou can use baseStyle instead.
alterDataYou can use domVisitors.onText instead. See Dom Tampering.
alterChildrenYou can use domVisitors.onElement instead. See Dom Tampering.
alterNodeYou can use domVisitors.onElement instead. See Dom Tampering.
allowWhitespaceNodesWhite-space collapsing is now fully supported. See Transient Render Engine, whitespace collapsing.

Other Props#

Props not listed in the above section are unchanged.

Migrating Custom Renderers#

Arguments Equivalence#

Let's start with a custom renderer from v5:

renderers.jsx
const renderers = {
hr: (htmlAttribs, children, convertedCSSStyles, passProps) => {
return /* Whatever */;
}
};

In v6, renderers are React components:

renderers.jsx
const renderers = {
hr: ({
tnode,
onPress,
propsFromParent,
sharedProps,
style,
textProps,
type,
viewProps,
InternalRenderer,
TDefaultRenderer
}) => {
return /* Whatever */;
}
};
tip

See CustomRendererProps for a detail on each of these props.

Let's see now how arguments map from v5 to v6:

Argument (v5)Prop Name (v6)Remarks
htmlAttribstnode.attributesThe TNode is the intermediary representation of the element to render. See Architecture.
childrenAlternative exists.You can still render children. However, instead of having access to the children as React elements, you can inspect tnode.children and render these with TNodeChildrenRenderer. This is much more flexible than the legacy API. See Custom Rendering.
convertedCSSStylesstyleThose styles are flatten and can be easily inspected.
passProps.renderersPropsAlternative exists.You can access renderers prop for a specific tag via useRendererProps hook.
passProps.nodeIndextnode.nodeIndex
passProps.transientChildrentnode.children
passProps.domNodetnode.domNode
passProps.parentWrappertypeEither "text" or "block".
passProps.datatnode.dataAvailable when tnode.type === 'text'
passProps.keyN/AKeys don't need to be used anymore since renderers are components. The key is handled by the parent (TNodeRenderer).
passProps.parentTagtnode.parent.tagName
passProps.onLinkPressAlternative exists.You can access this prop via useRendererProps('a').onPress.
passProps.tagsStylesNo Equivalent.
passProps.classesStylesNo Equivalent.
passProps.defaultTextPropstextProps
passProps.defaultWebViewPropssharedProps.defaultWebViewProps
passProps.computeEmbeddedMaxWidthsharedProps.computeEmbeddedMaxWidthA better option is to take advantage of useComputeMaxWidthForTag hook.
passProps.contentWidthAlternative exists.Access content width via useContentWidth hook.

Custom Tags#

Let's say we registered a renderer for <bluecircle> tag, which is non-standard. In v6, we must also register the element model for this tag. See Custom Rendering, registering a new tag.

Other Exports#

ExportRemarks
getParentsTagsRecursivelyDiscontinued.
getClosestNodeParentByTagDiscontinued.
constructStylesDiscontinued. Not applicable since the styling logic has been totaly reframed and should be much more consistent.
domNodeToHTMLStringUnchanged.