How to make conditional rendering in reacte?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
6 views
Good afternoon, walk around the loop the array data? you need to slide every 3 to wrap to a new "row". please tell me how to implement it.
{slides.map((slide, index ) => (
index !== 0 &&index % 3 === 2) ? : "
the "component" Item
key={index}
data={slide}
/ "closeComponent"
slides.length=== index + 1 || index % 3 === 1 ? : "
))}
by | 6 views

2 Answers

0 like 0 dislike
const rows = slides.reduce((acc, el, i) => { if(i % 3 === 0) acc.push([]); acc[acc.length-1].push(el); return acc; }, []); return ( {rows.map((row, index) => ( {row.map((slide, i) => )} ))} );
by
0 like 0 dislike
function createWrappedSlides(slides, count = 3) { const wrappedSlides = []; for (let i = 0; i < slides.length; i += count) { wrappedSlides.push(slides.slice(i, i + count)); } return wrappedSlides; } createWrappedSlides(slides).map((slide, i) => )
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
asked Jun 11, 2019 by Bufore
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
110,608 questions
257,186 answers
0 comments
35,573 users