at the moment im fetching data and render it as map into my components.
{props.posts.map((post) =>(
<PostBasic post={post}></PostBasic>
))}
My function to fetch data:
async function fetchMoreData() {
console.log('feed ' + feed)
const fetchedData = await axios.get('/api/fetchfeed', {params:{dataCount: feed.length}})
console.log(fetchedData.data)
let newData;
if(fetchedData.data.length != 0){
for (let i = 0; i <= fetchedData.data.length; i++) {
setNewData([...newData, fetchedData.data[i]])
}
setFeed([...feed, newData])
How can I get the length of the rendered components and place another different component at a random position? The result I'm expecting for example If we got 5 Posts from fetch is:
- <PostBasic>
- <MyOtherComponent> <---- Randomly placed
- <PostBasic>
- <PostBasic>
- <PostBasic>
- <PostBasic>
How to achieve this? Thanks