← SnippetsConditional RenderingTrick for writing cleaner conditional renderingSep 3, 2022 · 1 min readRenderIf.tsxtype Props = { children: React.ReactNode; isTrue: boolean; }; export const RenderIf = ({ children, isTrue }: Props) => { return <>{isTrue ? children : null}</>; }; Usage import { useState } from 'react'; import { RenderIf } from '@/components/RenderIf'; function App() { const [value, setValue] = useState(4); return ( <> <p>Current value: {value}</p> <RenderIf isTrue={value === 4}> <h1>Value is 4! I will rendered</h1> </RenderIf> </> ); }