如何在reactintl中新建一行?

我有一个问题 - 如何在 react intl 中创建一个新行?我把我的翻译放在文件中,如:

[LOCALES.ENGLISH]: {
        'hello': 'Hello',
        }

回答

使用参数添加<br/>标签:

const messages = {
  MESSAGE: {
    id: "message",
    defaultMessage: "<p>Message with {br} linebreaks</p>"
  }
};

export default function App() {
  return (
    <IntlProvider locale="en" messages={messages}>
      <div className="App">
        <FormattedMessage
          {...messages.MESSAGE}
          values={{
            p: (...chunks) => <p>{chunks}</p>,
            br: <br />
          }}
        />
      </div>
    </IntlProvider>
  );
}

完整沙箱:https : //codesandbox.io/s/formattedmessage-key-error-6kx6c? file =/ src/ App.js


以上是如何在reactintl中新建一行?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>