简体   繁体   English

在 react js 中渲染 2 个组件

[英]rendering 2 components in react js

I stuck on one problem in my project I use 2 different components one is a card and second is a chart and i show the API data on that component but when I rendering both components it will be override to each other how I can solve this problem我在我的项目中遇到了一个问题 我使用了 2 个不同的组件,一个是卡片,第二个是图表,我在该组件上显示 API 数据,但是当我渲染这两个组件时,它将相互覆盖我如何解决这个问题

render() {
    return (
        <div style={{ display: "flex" }}>
            {
                this.state.data.map((item, index) => {
                    return <div key={index} style={{ width: "300px" }}>
                        <Cards value={item} title={item.bikeId} time={item.timeStamp} />
                        <Speedometer speed={item.speed} />
                    </div>
                })
            }
        </div>        
    )
}

card and speedometer are two different components it will be created based on API response卡和车速表是两个不同的组件,它将根据 API 响应创建

By Overriding, if you mean the components are overlapping on one another, that might probably a CSS issue, try putting a <br> between both the components.通过覆盖,如果您的意思是组件彼此重叠,这可能是 CSS 问题,请尝试在两个组件之间放置一个<br>

or或者

try increasing the width to 100% and remove that 300px尝试将宽度增加到 100% 并删除 300px

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

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