Created
October 14, 2025 09:03
-
-
Save Aminigbo/720d00c2737e3c8aada0e7fc056d86da to your computer and use it in GitHub Desktop.
Explanation: The map() function loops through each post. After every two posts ((index + 1) % 2 === 0), an Ad Banner view is rendered. The React.Fragment wrapper lets you return both the post and optional ad banner together without an extra container.
This file contains hidden or 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"; | |
| import { View, Text } from "react-native"; | |
| const posts = [ | |
| { | |
| title: "Behind the Scenes: Launch Day", | |
| date: "2025-10-14T10:00:00Z", | |
| description: "A quick look at what went into today’s release and what’s next.", | |
| }, | |
| { | |
| title: "Feature Spotlight: Smart Notifications", | |
| date: "2025-10-12T09:30:00Z", | |
| description: "Stay in the loop without the noise. Here’s how it works.", | |
| }, | |
| { | |
| title: "Customer Story: Scaling with Confidence", | |
| date: "2025-10-09T15:45:00Z", | |
| description: "How one team cut response times by 40% using our platform.", | |
| }, | |
| { | |
| title: "Tips: Getting More from Your Dashboard", | |
| date: "2025-10-05T08:15:00Z", | |
| description: "Five quick tweaks to surface metrics that matter.", | |
| }, | |
| { | |
| title: "Roadmap Update: Q4 Priorities", | |
| date: "2025-10-01T12:00:00Z", | |
| description: "What we’re building next and how you can weigh in.", | |
| }, | |
| ]; | |
| const PostList = () => { | |
| return ( | |
| <View style={{ padding: 16 }}> | |
| {posts.map((post, index) => ( | |
| <React.Fragment key={index}> | |
| <View | |
| style={{ | |
| marginBottom: 20, | |
| padding: 16, | |
| borderWidth: 1, | |
| borderColor: "#ccc", | |
| borderRadius: 8, | |
| }} | |
| > | |
| <Text style={{ fontWeight: "bold", fontSize: 16 }}> | |
| {post.title} | |
| </Text> | |
| <Text style={{ color: "#666", marginVertical: 4 }}> | |
| {new Date(post.date).toDateString()} | |
| </Text> | |
| <Text>{post.description}</Text> | |
| </View> | |
| {/* Render Ad Banner after every 2 posts */} | |
| {(index + 1) % 2 === 0 && index !== posts.length - 1 && ( | |
| <View | |
| style={{ | |
| backgroundColor: "#f1f1f1", | |
| padding: 20, | |
| alignItems: "center", | |
| borderRadius: 8, | |
| marginBottom: 20, | |
| }} | |
| > | |
| <Text style={{ fontWeight: "bold" }}>Ad Banner</Text> | |
| </View> | |
| )} | |
| </React.Fragment> | |
| ))} | |
| </View> | |
| ); | |
| }; | |
| export default PostList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment