Using the react-intl FormattedMessage component, we’ll learn how to render content conditionally in our messages based on a number provided as a prop.

You’ll also learn the syntax necessary to render strings using a plural string matcher.

averageRating: 'Average Rating: {avg} ({count, plural, =0 {No reviews Yet!} one {# review} other {# reviews}})',

Based on the variable 'count', if =0, then show 'no review yet'; if equals to one, then showing '1 review', if more than one, then showing ''# reveiws", "#" will be replaced by the actual number.

    const avgRating = book.reviews.length ? round(meanBy(book.reviews, (r) => r.rating), 2): 0;<h3><FormattedMessage id="detail.averageRating" values={{avg: avgRating,count: book.reviews.length}} /></h3>

转载于:https://www.cnblogs.com/Answer1215/p/7263523.html

[React Intl] Render Content Based on a Number using react-intl FormattedMessage (plural)相关推荐

  1. react render没更新_web前端教程分享React学习笔记(一)

    web前端教程分享React学习笔记(一),React的起源和发展:React 起源于 Facebook 的内部项目,因为该公司对市场上所有 JavaScript MVC 框架,都不满意,就决定自己写 ...

  2. TypeScript + React 学习render props

    ###前言 一直想学学TypeScript,尝试尝试带类型的js怎么写,有啥优点.正好这两天有时间结合着react写写小例子. 搭建环境 不想折腾webpack来自己配ts+react的环境就用typ ...

  3. [react] 请说说你对react的render方法的理解

    [react] 请说说你对react的render方法的理解 render是class组件中必须被重载的方法,组件执行render方法的条件如下: 初始渲染 this.setState方法,参数不能为 ...

  4. [react] React的render中可以写{if else}这样的判断吗?

    [react] React的render中可以写{if else}这样的判断吗? 不可以,可以用 三元运算符或者 与运算符操作 个人简介 我是歌谣,欢迎和大家一起交流前后端知识.放弃很容易, 但坚持一 ...

  5. 在React的render方法中使用箭头函数

    在 React 组件中绑定点击事件通常的做法使用 class 属性. class Foo extends Component {handleClick = () => {console.log( ...

  6. Class-Balanced Loss Based on Effective Number of Samples - 1 - 论文学习

    https://arxiv.org/pdf/1901.05555.pdf skewed 倾斜的,歪斜的 heuristic 启发式的 interpolated插值 focal 焦点的 compleme ...

  7. react中render重绘时,constructor是否执行问题

    结论是 react中,state,props,context三兄弟改变时,都会引起render重绘,但是重绘并不会导致构造器 constructor重新执行. 父组件套子组件时,当父组件的render ...

  8. react 的 render 函数

    JSON2DOM = react的render函数 文章目录 JSON2DOM = react的render函数 功能介绍 实现 _render 函数 测试结果 功能介绍 const vnode = ...

  9. 基于内容的图片检索CBIR(Content Based Image Retrieval)简介

    原文链接:https://blog.csdn.net/carson2005/article/details/9304913 传统的图像检索过程,先通过人工对图像进行文字标注,再利用关键字来检索图像,这 ...

最新文章

  1. c语言中'.'与'-'的区别
  2. 怒肝三个月啃完这110道面试题,跳槽薪资翻倍
  3. Maven引用本地jar并在打war包时引用jar
  4. mongodb分页优化
  5. 51单片机蜂鸣器播放音乐
  6. 数字签名原理及其应用详解
  7. vue引入图片的方式
  8. 明朝首辅/太师,辅佐明朝四代国之重臣杨士奇后世传人在松滋
  9. 智能手机和PC降温,英伟达英特尔等把钱砸向了AI
  10. 深度学习目标检测方法综述
  11. Rational Rose7.0的安装(含图详解)
  12. 160cracked-1
  13. 旗帜软件工作室年会总结
  14. Windows 10 下载(1)
  15. nchar , char , nvarchar , varchar 的区别
  16. 数据结构与算法之美笔记——基础篇(中):树,二叉树,二叉查找树,平衡二叉查找树,红黑树,递归树,堆
  17. 如何保护电子邮箱安全?163邮箱安全吗?
  18. centos7 安装 swoole
  19. Jetson nano 摄像头二维码识别 Opencv zbar QT
  20. FPGA实例06——FPGA驱动超声波模块

热门文章

  1. MATLAB GUI制作快速入门
  2. 超强音质国产半入耳耳机来袭!NANK南卡首款蓝牙5.3小音舱发布
  3. linux socket send函数和recv函数详解以及修改缓冲区大小
  4. Typecho魔改版二次元风格G主题
  5. Unity 立体3D VR的实现
  6. Ionic Mobile
  7. app功耗测试-adb命令
  8. 3D扫描齿科应用 为病患再造完美牙齿
  9. win专业版运行adb命令行报“无法定位程序输入点 ucrtbase._strtod_l 于动态链接库 api-ms-win-crt-convert-l1-1-0.dll 上。 ”问题解决
  10. Weblogic 常见漏洞分析与利用