We help IT Professionals succeed at work.
Get Started
Troubleshooting Question

condition statement within react return causes syntax error

jblayney
jblayney asked
on
12 Views
Last Modified: 2021-01-09
Hello,

I am having syntax issues within a return. I am trying to check if an array item exists..  the issue is how I am writing the code I think..

the code causing the error is
{ nodes.childItems   ? "has child"  : "no child "   }

the error is
Syntax error: Unexpected token, expected ","

How do I write this within my return?
 

      const MyNav = () => {
      const [allNavItems, setAllNavItems] = useState(null);
   
      useEffect(() => {
        const run = async () => {
          const items = await getNavMenu();
         
          setAllNavItems(items);
        };
   
        run();
      }, []);
   
      if (!allNavItems) return null;
   
      return (
         
     <Navbar bg="light" expand="lg">
      <Navbar.Brand href="#home">React-Bootstrap</Navbar.Brand>
      <Navbar.Toggle aria-controls="basic-navbar-nav" />
      <Navbar.Collapse id="basic-navbar-nav">
            <Nav className="mr-auto">
                  <Nav.Link href="/">Home</Nav.Link>
         
              {allNavItems.menuItems && allNavItems.menuItems.nodes.map((nodes) => (
         
         
                <Nav.Link href={nodes.path}>    {nodes.label}, {nodes.parentId}, {nodes.id} </Nav.Link>
                      { nodes.childItems   ? "has child"  : "no child "   }
         
         
                 
              ))}
           
   
   
            </Nav>
        </Navbar.Collapse>
    </Navbar>
      )
    }

 


Comment
Watch Question
Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE