Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Collapse
exlends
Категории
  1. Home
  2. Categories
  3. Фронтенд
  4. React
  5. Cannot update a component while rendering a different component

Cannot update a component while rendering a different component

Scheduled Pinned Locked Moved React
1 Posts 1 Posters 23 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • kirilljsxK Offline
    kirilljsxK Offline
    kirilljsx
    js
    wrote on last edited by
    #1
    Cannot update a component while rendering a different component
    

    Причина: Вызов setState во время рендеринга другого компонента.

    Пример:

    function Parent() {
      const [state, setState] = useState();
      return <Child setState={setState} />;
    }
    
    function Child({ setState }) {
      setState(42); // Вызов здесь запрещен!
      return <div>...</div>;
    }
    

    Решение: Использовать useEffect для сайд-эффектов.

    1 Reply Last reply
    0

    Категории

    • Главная
    • Новости
    • Фронтенд
    • Бекенд
    • Языки программирования

    Контакты

    • Сотрудничество
    • info@exlends.com
    • Наш чат
    • Наш ТГ канал

    © 2024 - 2025 ExLends, Inc. Все права защищены.

    Политика конфиденциальности
    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups