D
D
Dmitry Maksimyuk2021-06-17 23:20:40
React
Dmitry Maksimyuk, 2021-06-17 23:20:40

Why is there a memory leak here?

I'm making a game, it has a store in which there are several panels, indicates that in this code, a leak:

const Businesses = () => {
  // массив бизнесов
  const getBusinesses = useRecoilValue(GET_BUSINESSES)
  const businesses = getBusinesses.map((item: any) => <ShopItems
      key={`id${item.id}`}
      img={item.img}
      title={item.title}
      requirements={`Стоимость: ${item.costString} ${SYMBOLS_RUB}`}
      status={`Доходность: ${item.earningsString} ${SYMBOLS_RUB}/час`}
    />)

  return (
    <Div>
      {businesses}
    </Div >
  )
}

I have an assumption that because of the map, but ... how much I used it, this did not happen ...
It only occurs when I re-pass to the section with this component
60cbae4c1a892162811695.png
Thanks for the help!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2021-06-17
@karminski

Typically, this error occurs as a result of performing an asynchronous operation inside the useEffect hook. To solve the problem, there should be a return inside the hook. See here https://ru.reactjs.org/docs/hooks-effect.html components with reset effects

A
abberati, 2021-06-18
@abberati

But I don't use useEffect

You are not. In the specified component, there is a call to a single (custom) hook - useRecoilValue. Custom hooks are functions that call regular hooks, like useEffect

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question