Maintenance of all React components



  • There's a component of LoadingScreen - that's what loader is. I need to hide it when the rest of this page are downloaded. I'm going through the huk useState, but I can't find the conditions to change the steta isLoading.

    const [isLoading, setIsLoading] = useState(true);
    

    useEffect(() => {
    // Какое-то условие, чтобы изменить isLoading на false
    setIsLoading(false);
    }, []);

    return (
    <>
    {isLoading
    ? <LoadingScreen /
    : //Компоненты страницы
    }
    </>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>



  • https://ru.reactjs.org/docs/hooks-effect.html#tip-optimizing-performance-by-skipping-effects Says:

    Don't forget that React is delaying useEffect until the browser draws all the changes, ♪ ♪

    So you don't need to add a condition. Works like this:

    • Randerite.
    • Implemented useEffect() and leaves one. isLoading == false before the end of the life cycle (because of empty-sized construction)
    • Reindeer is already relatively new. isLoading


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2