Created
January 22, 2021 08:58
-
-
Save ComradeCat24/b1bade77a3a061518277ff20df4c0eef to your computer and use it in GitHub Desktop.
For-loop in JSX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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