How to stop a React component from rendering

1 · Amit Merchant · March 18, 2023, 1:38 p.m.
In React, when you want don’t want a component to render based on some condition, you might reach for short-circuiting to achieve the same. Check the following example. import Header from "./Header"; export default function App() { const shouldRender = true; return ( <> {shouldRender && <Header />} <div className="App"> <h1>App Body</h1> <h2>This is app body</h2> </div> </> ); } As you can tell, the Header component will render if the shouldRend...