Search code examples
javascriptreactjsi18nextreact-i18next

How to pass i18n localization text in to property of array


Hi I'm trying to pass i18n localization text in to property of the array but it showing me the error on compiling.

 const columns = [
{
  name:  {i18n.t('Stock Data')},
  selector: 'stockSymbol'
},
{
  name: 'Stock Name',
  selector: 'stockNameEn'
}]

The error is saying that , expected . how can I solve it ?


Solution

  • So to make it clear:

    In plain JavaScript (except jsx) {} means an object or a code block that's why it's not what you want.

    i18n.t('Stock Data') returns a string that's why name: i18n.t('Stock Data') is a solution.