We sometimes just want to return a couple of elements next to one another from a React functional component, without adding a wrapper component which only purpose would be to wrap elements that we want to render.

In this one minute lesson we are going to learn how to solve this problem by returning an array of components and as such - avoid adding unnecessary div wrappers.

Way 1:

import React from "react";
import "./App.css"; const App = () => {
return (
<>
<div className="box">One</div>,
<div className="box">Two</div>,
<div className="box">Three</div>
</>
);
}; export default App;

Way 2:

import React from "react";
import "./App.css"; const App = () => {
return [
<div className="box">One</div>,
<div className="box">Two</div>,
<div className="box">Three</div>
];
}; export default App;

[React] Return a list of elements from a functional component in React的更多相关文章

  1. [React] Refactor a Stateful List Component to a Functional Component with React PowerPlug

    In this lesson we'll look at React PowerPlug's <List /> component by refactoring a normal clas ...

  2. React Native Android原生模块开发实战|教程|心得|怎样创建React Native Android原生模块

    尊重版权,未经授权不得转载 本文出自:贾鹏辉的技术博客(http://blog.csdn.net/fengyuzhengfan/article/details/54691503) 告诉大家一个好消息. ...

  3. React 16 源码瞎几把解读 【二】 react组件的解析过程

    一.一个真正的react组件编译后长啥样? 我们瞎几把解读了react 虚拟dom对象是怎么生成的,生成了一个什么样的解构.一个react组件不光由若干个这些嵌套的虚拟dom对象组成,还包括各种生命周 ...

  4. [React] Refactor a Class Component with React hooks to a Function

    We have a render prop based class component that allows us to make a GraphQL request with a given qu ...

  5. React.Component 与 React.PureComponent(React之性能优化)

    前言 先说说 shouldComponentUpdate 提起React.PureComponent,我们还要从一个生命周期函数 shouldComponentUpdate 说起,从函数名字我们就能看 ...

  6. react做股票、期货交易遇到的问题(不完全是react)及解决方法。

    公司项目主要是做股票及期货行情展示及交易,h5相应的做了一些功能---可以看行情图及模拟交易,实盘交易存在一定的风险,老板希望做自己的产品,这样h5就尴尬了,不过没关系,项目里还是有一定技术含量的-- ...

  7. react 创建组件 (四)Stateless Functional Component

    上面我们提到的创建组件的方式,都是用来创建包含状态和用户交互的复杂组件,当组件本身只是用来展示,所有数据都是通过props传入的时候,我们便可以使用Stateless Functional Compo ...

  8. React.Component 和 React.PureComponent 、React.memo 的区别

    一 结论 React.Component 是没有做任何渲染优化的,但凡调用this.setState 就会执行render的刷新操作. React.PureComponent 是继承自Componen ...

  9. React报错之React hook 'useState' cannot be called in a class component

    正文从这开始~ 总览 当我们尝试在类组件中使用useState 钩子时,会产生"React hook 'useState' cannot be called in a class compo ...

随机推荐

  1. selenium 多窗口切换(windows)

    在web应用中,常常会遇见点击某个链接会弹出一个新的窗口,或者是相互关联的web应用 ,这样要去操作新窗口中的元素,这时就需要主机切换到新窗口进行操作..WebDriver 提供了switchTo() ...

  2. testng+IEDriverServer+yum+tomcat下载软件包

    testng框架链接:http://files.cnblogs.com/files/linxinmeng/testng%EF%BC%88selenium%E6%A1%86%E6%9E%B6%EF%BC ...

  3. foreach 与 Linq的 Select 效率问题

    Resharper 是一个非常强大的C#编程辅助工具,有着非常强的提示功能,代码纠正,代码简化等等 在编码过程中注意到这么一件事,可能是大家经常会遇到的: 遍历某个集合,然后经过处理生成另外一个集合, ...

  4. 【我要学python】愣头青之初安装就打了一记耳光

    pycharm安装好后创建项目出现interpreter field is empty,导致pycharm无法使用. 这是因为python没有安装好,重新自定义安装一次即可 下载地址:https:// ...

  5. Codeforces #447 Div2 E

    #447 Div2 E 题意 给出一个由有向边构成的图,每条边上有蘑菇,假设有 \(n\) 个蘑菇,那么第一次走过这条边可以获得 \(n\) 个蘑菇,第二次 \(n-1\),第三次 \(n-1-2\) ...

  6. 洛谷——P1163 银行贷款

    P1163 银行贷款 题目描述 当一个人从银行贷款后,在一段时间内他(她)将不得不每月偿还固定的分期付款.这个问题要求计算出贷款者向银行支付的利率.假设利率按月累计. 输入输出格式 输入格式: 输入文 ...

  7. Linux命令之crontab

    crontab [-u user] file crontab [-u user] [-l | -r | -e] [-i] [-s] crontab命令被用来提交和管理用户需要周期性执行的任务,与win ...

  8. 第2天-css快速入门

    css是什么 css(cascading style sheet,可以译为“层叠样式表”),是一组格式设置规则,用于控制web页面的外观 如何让一个标签具有样式 第一步:必须保证引入方式正确 第二步: ...

  9. Difference between [0-9], [[:digit:]] and \d

    Yes, it is [[:digit:]] ~ [0-9] ~ \d (where ~ means aproximate).In most programming languages (where ...

  10. BZOJ 1878 [SDOI2009]HH的项链(扫描线+树状数组)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1878 [题目大意] 给出一个数列,给出m个查询,每次查询一个区间中不相同的数字个数 [ ...