简体   繁体   English

将数组渲染为带有样式组件的行

[英]Render an array to rows with styled-component

I have a simple array here that I am trying to render into a grid.我在这里有一个简单的数组,我试图将其渲染到网格中。

This code below renders the array as:下面的代码将数组呈现为:

HAMDDN汉密尔顿

I want to render it such that the following will result in a different row我想呈现它,以便以下将导致不同的行

HA
MD
DN

Any thoughts?有什么想法吗? The full code is below.完整代码如下。 I know this is a simple task but I am a newbie.我知道这是一项简单的任务,但我是新手。 Thanks!谢谢!

import React from 'react';
import styled from 'styled-components';
import Page from '../Shared/Page'

export const StateGrid = styled.div`
         display:inline-block;
       `;

const list =[
    "HA", "MD", "DN"
]

function States () {
     return (
       <Page name="statistics">
           <StateGrid>{list}</StateGrid>
       </Page>
     );
}

export default function() {
  return (
    <States/>
  );
}

Use map()使用地图()

The map() method creates a new array populated with the results of calling a provided function on every element in the calling array. map() 方法创建一个新数组,其中填充了对调用数组中的每个元素调用提供的函数的结果。

<StateGrid>
  {list.map(item => (
    <div>{item}</div>
  ))}
</StateGrid>

编辑华丽的共振-4c63d

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM