Nowe zachowanie Strict Modea w React

0

W tym artykule https://blog.logrocket.com/using-strict-mode-react-18-guide-new-behaviors/ znalazłem informację, że w React 18 zmienia się nieco zachowanie Strict Modea.

"React v18 introduced new strict mode behavior regarding unmounting and remounting. Now, each element will be unmounted and remounted with the same state and effects as when the element was mounted for the first time."

Jednak ja nic takiego nie zauważyłem w najnowszej wersji Reacta 18. Czy w tym artykule znajdują się nieprawdziwe informacje ?

0

ja zauważyłem, bo mi się requesty do backendu w useEffect zaczęły wykonywać 2x na start

0
snowflake2137 napisał(a):

ja zauważyłem, bo mi się requesty do backendu w useEffect zaczęły wykonywać 2x na start

Czy nie masz na myśli tego zachowania, które zostało tu opisane?: https://stackoverflow.com/questions/72112028/does-strict-mode-work-differently-with-react-18/72112129#72112129

Bo ja o czym innym w pierwszym poście napisałem.

Tu: https://refine.dev/blog/react-strict-mode-in-react-18/#whats-new-in-react-v180

zostało opisane, że chcą wprowadzić to w przyszłości:

"With React 18, Strict Mode can now handle mounting and unmounting components and, in future, preserve and restore their state on subsequent mounts."

1
snowflake2137 napisał(a):

ja zauważyłem, bo mi się requesty do backendu w useEffect zaczęły wykonywać 2x na start

To tylko znak, że źle używasz useEffecta. Właśnie po to zostały w React 18 wprowadzone te zmiany, by bić po oczach ludziom tymi błędami i by przygotować ich na planowane zmiany.

In the future, we’d like to add a feature that allows React to add and remove sections of the UI while preserving state. For example, when a user tabs away from a screen and back, React should be able to immediately show the previous screen. To do this, React would unmount and remount trees using the same component state as before.

This feature will give React apps better performance out-of-the-box, but requires components to be resilient to effects being mounted and destroyed multiple times. Most effects will work without any changes, but some effects assume they are only mounted or destroyed once.

To help surface these issues, React 18 introduces a new development-only check to Strict Mode. This new check will automatically unmount and remount every component, whenever a component mounts for the first time, restoring the previous state on the second mount.

1 użytkowników online, w tym zalogowanych: 0, gości: 1