I have built a sample project where I am receiving dynamic data from a back end server. The data is being stored in an array
Then I have built this input box component.
//data_View is a functional Component
const data_View = (props) =>
(
<div className="form-input">
<input style={{backgroundColor: `${props.backgroundColor}`}}
type="text"
name={props.dataId}
value={props.content}
/>
</div>
);
data_View.propTypes = {
dataId:PropTypes.string,
content: PropTypes.string,
};
export default data_View;
And then in my App.js, depending on size of the array (which is static, currently 3) I am rendering data_View component e times, each with a different prop value , like this:
<div className="Data3">
<data_View backgroundColor={this.state.bColor[2]}
content = {this.state.value[2]}
name = "data3"
/>
</div>
This works perfectly per my desire.
Next I tried replacing the input box with Card from Material-UI. In doing so I have learned that only one Card is being rendered at a time.
Unless I use map(), something like this as per the example I found...
const topics = [
{
name: "data1",
value: "3",
},
{
name: "data2",
value: "5"
}
]
{topics.map(data=>(
<Card style={{backgroundColor:`${props.backgroundColor}`}}>
<CardActionArea >
<CardMedia
...
/>
</CardActionAre>
</Card>
))}
I can't figure out how can I refactor the above example to fit my scenario. I cannot create an array like the example because I am getting a stream of data from the server and that is constantly changing.
Any thoughts, suggestion is really appreciated.
Thank you