Skip to content

Instantly share code, notes, and snippets.

@ComradeCat24
Created January 22, 2021 08:58
Show Gist options
  • Save ComradeCat24/b1bade77a3a061518277ff20df4c0eef to your computer and use it in GitHub Desktop.
Save ComradeCat24/b1bade77a3a061518277ff20df4c0eef to your computer and use it in GitHub Desktop.
For-loop in JSX
import React from "react";
const RFor = ({ data, renderItem }) => {
return data.map((item) => renderItem(item));
};
const data = ["i1", "i2", "i3", "i4", "i5", "i6", "i7", "i8", "i9", "i10"];
const Box = ({ item }) => (
<div>
<h6>{item}</h6>
</div>
);
const App = () => {
return (
<div>
<RFor data={data} renderItem={(item) => <Box item={item} />} />
</div>
);
};
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment