UNPKG

@roderickhsiao/react-i13n

Version:

[Experiment] React I13n provides a performant and scalable solution to application instrumentation.

35 lines (30 loc) 1.03 kB
/** * Copyright 2015 - Present, Yahoo Inc. * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. */ import { useRef, useState } from 'react'; import I13nNode from '../core/I13nNode'; var useI13nNode = (_ref) => { var { i13nInstance: reactI13n, i13nModel, isLeafNode, parentI13nNode } = _ref; var i13nNodeRef = useRef(); var [i13nNode, setI13nNode] = useState(); var initI13nNode = () => { if (reactI13n && !i13nNode) { var _reactI13n$getI13nNod; // check if reactI13n is initialized successfully, otherwise return var I13nNodeClass = (_reactI13n$getI13nNod = reactI13n.getI13nNodeClass()) !== null && _reactI13n$getI13nNod !== void 0 ? _reactI13n$getI13nNod : I13nNode; i13nNodeRef.current = new I13nNodeClass(parentI13nNode, i13nModel, isLeafNode, reactI13n.isViewportEnabled()); setI13nNode(i13nNodeRef.current); } }; initI13nNode(); return { i13nNode: i13nNodeRef.current }; }; export default useI13nNode;