I have an array of objects coming from the server. I use this to display cards on the screen. I want to insert an "advertisements card" every X cards. I thought I'd done this on the web with the following code, but it seems to not be working with my react-native app.
class DeckArea extends React.Component {
constructor(props){
super(props);
}
render(){
let { data, likeJob } = this.props;
// place an object into the array of jobs data
data.jobs.forEach((item, i) => {
let remainder = i%4;
if (remainder === 0) {
console.log(remainder === 0)
data.jobs.splice(i, 0,{ isAd: true, _id: uuidV4() })
}
});
return (
<View style={styles.container}>
<Swipe
data={data.jobs}
renderCard={(job) => {
//check if isAd === true,
// if so, show the AdCard not the deck card
if (job.isAd) {
return <AdCard adsManager={adsManager} />
}
return <DeckCard job={job} isLikedCard={false} />
}}
/>
</View>
);
}
}
I've done some quick testing and the problem is definitely happening here:
data.jobs.forEach((item, i) => {
let remainder = i%4;
if (remainder === 0) {
console.log(remainder === 0)
data.jobs.splice(i, 0,{ isAd: true, _id: uuidV4()})
}
});
resulting in "attempted to assign to readonly property"
Additional resources: