Answer the question
In order to leave comments, you need to log in
How can this component be optimized?
Hey! Just started learning hooks so please don't throw rocks.
Actually, there is a component that should output N times another component.
N is the height of the screen / the height of the repeating component.
Implemented like this:
const Repeater = () => {
const items = Math.ceil(window.screen.height / 130);
return (
<div className="list">
{[...Array(items)].map((value, index) => (
<RepeatedComponent />
))}
</div>
);
};
export default Repeater ;
Answer the question
In order to leave comments, you need to log in
Can it be like this
const Repeater = () => {
const items = useMemo(() => {
const itemsCount = Math.ceil(window.screen.height / 130);
return Array.from(Array(itemsCount).keys())
}, [window.screen.height])
return (
<div className="list">
{items.map((value, index) => (
<RepeatedComponent key={value} />
))}
</div>
);
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question