DEV Community

Discussion on: Conditionally rendering JSX in React functions

Collapse
 
mrchedda profile image
mr chedda

The preferred method to conditionally render a component is:

export default function App(){
    { conditionalStatement && ( 
         <RenderedComponent /> 
    )}
}
Enter fullscreen mode Exit fullscreen mode

OR

export default function App(){
    { conditionalStatement ? ( 
        <RenderedComponentOne /> 
    ):( 
        <RenderedComponentTwo />
    )}
}
Enter fullscreen mode Exit fullscreen mode