React i18next如何影响渲染性能?

时间:2017-06-29 14:01:24

标签: performance reactjs i18next

i18next将如何影响React的表现呢?而且,它的插值机制与反应方式如何呈现动态变量呢?

鉴于以下

/区域设置/ {语言} /common.json

{
    "hello-world": "Hello, World",
    "interpolated": "Hello, {{ name }}"
}

i18next示例

// Import i18n config and translate function
const Example = function(ownProps) {
  { t } = ownProps; 
  return (
    <div>
      <h1>{ t('interpolated', { name: "World" }) }</h1>
      <h1>{ t('hello-world') }</h1>
    </div>
  );
};

export default translate('common', { i18n })(Example);

没有i18next的示例

const Example = function() {
  let name = "World";
  return (
    <div>
      <h1>Hello, World</h1>
      <h1>Hello, { name }</h1>
    </div>
  );
};

export default Example;

查找的差异有多大:

  • t('interpolated', { name: "World" }) vs Hello, { name }
  • t('hello-world') vs Hello, World

1 个答案:

答案 0 :(得分:0)

也许现在一切都被优化了,但是这个 repo 曾经显示了一些性能问题。

https://github.com/beheh/react-i18next-performance