abhijithvijayan / react-minimal-side-navigation

Minimal side navigation component for React
https://codesandbox.io/s/react-minimal-side-navigation-example-y299d?file=/src/components/NavSidebar.jsx
MIT License
67 stars 29 forks source link

Hide UL when empty object #15

Closed alexlovo closed 3 years ago

alexlovo commented 3 years ago

Is there a way to hide the

abhijithvijayan commented 3 years ago

can you create a sample codesandbox or attach the sample code here with screenshots @alexlovo

alexlovo commented 3 years ago
<Navigation
              activeItemId={location.pathname}
              onSelect={({ itemId }) => { history.push(itemId); }}
              items={[
              {
                  title: "Home",
                  itemId: "/",
                  elemBefore: () => <FontAwesomeIcon icon={faHome} />
                },
                isAuthorized ? {  //authorized is true or false
                  title: "Profile",
                  itemId: "/profile",
                  elemBefore: () => <FontAwesomeIcon icon={faUser} />,

                } : "",  // or adding an empty object {} instead of ""
            ]} />

Above is the sample, but its due to the div within the ul that it makes it look like something is there. Also it adds it because it iterates through each item regardless if its empty string ("") or empty object ({})

abhijithvijayan commented 3 years ago

@alexlovo this can be resolved with conditional spreading

https://codesandbox.io/s/react-minimal-side-navigation-example-forked-ojlec?file=/src/components/NavSidebar.jsx

abhijithvijayan commented 3 years ago

closing. feel free to re-open if it doesn't solve your issue

alexlovo commented 3 years ago

Yes that did work, I see what you mean now. Thank you for your quick response.