If your component needs i13n functionality, we will mirror an I13nNode in I13nTree for that component, we provide two ways for you to generate an I13nComponent. You can use following props to set what we want the I13nComponetn act like.
i13nModel- the i13nModel data object or a dynamic function returns the data object.isLeafNode- define if it's a leaf node or not, we will firecreatedevent for every node when it's created,isLeafNodewill help us to know if you want to do the action. e.g, you might only want to send out beacons to record links.bindClickEvent- define if want to bind a click handler or not.follow- define if click handler need to redirect users to destination after sending beacon or not. You could setfollow=falseand the handler would send out beacon but will not redirect users.scanLinks- other than replacing all links component, we provide a options to do that automatically, please note that this should be only used for some case you cannot replace the component, e.g., you are usingdangerouslySetInnerHTMLor the component has the dependencies of other projects.scanLinks.enable- enable the auto links-scanning procedure.scanLinks.tags- an array to define the tags you want it be be scanned, default to be['a', 'button'].- you can pass all the
propsyou need for the original component, we will pass them to the component.
The high order component integrates the functionalities of i13n, it returns a decorated component with full I13n functionality.
component- can be a string for native tags e.g.,a,buttonor a react component you createdefaultProps- defaultProps object, it would be the defaultpropsof that I13nNode, you can also pass options withpropsto overwrite it.options- options objectoptions.displayName- display name of the wrapper component, will fallback toI13n+ original display nameoptions.refToWrappedComponent- ref to the wrapped component, then you can use{i13nComponent}.refs[options.refToWrappedComponent]to access the wrapped component.options.skipUtilFunctionsByProps- true to prevent i13n util function to be passed viaprops.i13n
For example, if you want to enable link tracking, you will need to create an anchor with the createI13nNode and enable the click tracking.
import { createI13nNode } from 'react-i13n';
const I13nAnchor = createI13nNode('a', {
isLeafNode: true,
bindClickEvent: true,
follow: true
});
<I13nAnchor
i13nModel={i13nModel}
>
...
</I13nAnchor>;If you have a use case where you cannot replace the links with I13n Component, i.e, when using dangerouslySetInnerHTML. You can integrate the scanLinks options to automatically track these links. This option should be used sparingly since it can create additional DOM manipulations.
import { createI13nNode } from 'react-i13n';
const I13nDiv = createI13nNode('div', {
isLeafNode: false,
bindClickEvent: false,
follow: false,
scanLinks: {
enable: true,
tags: ['a', 'button']
}
});
<I13nDiv
i13nModel={i13nModel}
>
// the links inside will be scanned and tracked
// the i13n data will apply the i13nModel from I13nDiv
<a href="/foo">foo</a>
<button>bar</button>
</I13nDiv>;You will get i13n util functions via this.props.i13n by using createI13nNode, more detail please refer to util functions.