V
V
Vladimir2020-02-14 22:45:03
JavaScript
Vladimir, 2020-02-14 22:45:03

Why does the application freeze when building the component tree?

Good evening. Please tell me why it works:

export default function TopBar() {
    return (
        <Router>

            <SelectNavigation />

        </Router>
    )
}

function SelectNavigation() {

    // if (window.innerWidth > 900) {
    //
         return (
            <nav className='nav-computer'>
                //<NavigationTop items={navigationItems}/> <===============
                <div className="logo">
                    <Link to='/'>
                        <div className="first-child">{logo.firstChild}</div>
                        <div className="last-child">{logo.lastChild}</div>
                    </Link>
                </div>
            </nav>
        )

    // } else if (window.innerWidth < 900 && window.innerWidth > 500) {
    //     return (
    //         <nav className='nav-tablet'>
    //             <Navigation items={navigationTablet}/>
    //             <div className="logo">
    //                 <Link to='/'>
    //                     <div className="first-child">{logo.firstChild}</div>
    //                     <div className="last-child">{logo.lastChild}</div>
    //                 </Link>
    //             </div>
    //         </nav>
    //     )
    // } else if (window.innerWidth < 500) {
    //
    //     return (
    //         <nav className='nav-mobile'>
    //             <Navigation items={navigationMobile}/>
    //             <div className="logo">
    //                 <Link to='/'>
    //                     <div className="first-child">{logo.firstChild}</div>
    //                     <div className="last-child">{logo.lastChild}</div>
    //                 </Link>
    //             </div>
    //         </nav>
    //     )
    // }
}

const NavigationTop = ({ items }) =>
    items instanceof Array && items.length
        ? <ul>
            {items.map(n => (
                <li key={n.id}>
                    <Link to='/'>{n.title}</Link>
                    <NavigationTop items={n.children} />
                </li>
            ))}
        </ul>
        : null;


and this is not:

export default function TopBar() {
    return (
        <Router>

            <SelectNavigation />

        </Router>
    )
}

function SelectNavigation() {

    // if (window.innerWidth > 900) {
    //
         return (
            <nav className='nav-computer'>
                <NavigationTop items={navigationItems}/>
                <div className="logo">
                    <Link to='/'>
                        <div className="first-child">{logo.firstChild}</div>
                        <div className="last-child">{logo.lastChild}</div>
                    </Link>
                </div>
            </nav>
        )

    // } else if (window.innerWidth < 900 && window.innerWidth > 500) {
    //     return (
    //         <nav className='nav-tablet'>
    //             <Navigation items={navigationTablet}/>
    //             <div className="logo">
    //                 <Link to='/'>
    //                     <div className="first-child">{logo.firstChild}</div>
    //                     <div className="last-child">{logo.lastChild}</div>
    //                 </Link>
    //             </div>
    //         </nav>
    //     )
    // } else if (window.innerWidth < 500) {
    //
    //     return (
    //         <nav className='nav-mobile'>
    //             <Navigation items={navigationMobile}/>
    //             <div className="logo">
    //                 <Link to='/'>
    //                     <div className="first-child">{logo.firstChild}</div>
    //                     <div className="last-child">{logo.lastChild}</div>
    //                 </Link>
    //             </div>
    //         </nav>
    //     )
    // }
}

const NavigationTop = ({ items }) =>
    items instanceof Array && items.length
        ? <ul>
            {items.map(n => (
                <li key={n.id}>
                    <Link to='/'>{n.title}</Link>
                    <NavigationTop items={n.children} />
                </li>
            ))}
        </ul>
        : null;


Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question