Answer the question
In order to leave comments, you need to log in
Why is there an error when using useMemo?
There is this component:
import React from "react";
import styles from './styles/main.scss';
interface PaginationProps {
itemsCount: number;
}
const Pagination: React.FC<PaginationProps> = (props) => {
const { itemsCount } = props;
const items = React.useMemo(() => {
return [...Array(itemsCount).keys()].reverse();
}, [itemsCount]);
return (
<ul className={styles['pagination']}>
{items.map((itemNumber) => {
if (!itemNumber) {
return null;
}
return (
<li
className={styles['pagination__item']}
key={itemNumber}
>
{itemNumber}
</li>
);
})}
</ul>
);
};
Pagination.defaultProps = {
itemsCount: 0,
};
export default Pagination;
Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
Answer the question
In order to leave comments, you need to log in
I forgot to point out that the problem occurred when using module federation. When I rummaged through the same version of react for all components, the problem disappeared, and other similar
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question