joplin-notes/joplin notion extension/Web Development/React/Tips/ternary operator for routing.md
2026-11-04 00:33:23 +05:30

523 B

ternary operator for routing

When using {} for js expression make sure to wrap in under any component or element whether it is empty like <> </>


const [route,setRoute]=useState('home')
return (
    <>
      {route === "home" ? (
        <div className="App">
          <Nav />
          <Article
            files={files}
            setFiles={setFiles}
            category={category}
            setCategory={setCategory}
          />
        </div>
      ) : (
        <Output />
      )}
    </>
  );