JSX tree is too deeply nested. Found 5 levels of nesting
7class HeaderNav extends Component {
8 render() {
9 return (
10 <Menu borderless className="top-menu" fixed="top">11 <Menu.Item header className="logo">
12 <Link to="/"><Image src={Logo} size="tiny" /></Link>
13 </Menu.Item>
JSX tree is too deeply nested. Found 5 levels of nesting
7 const horizontal = props.horizontal ? 'horizontal' : null;
8
9 return (
10 <div className={['video-preview', horizontal].join(' ')}>11 <div className="image-container">
12 <Link to={`/watch/${props.id}`}>
13 <Image src={props.url} />
JSX tree is too deeply nested. Found 5 levels of nesting
20 }
21
22 return (
23 <Fragment>24 <div className="video-infobox">
25 <Image className="channel-image" src="https://via.placeholder.com/48x48" circular />
26 <div className="video-info">
Description
Nesting JSX elements too deeply can confuse developers reading the code. To make maintenance and refactoring easier, DeepSource recommends limiting the maximum JSX tree depth to 4.
Code that looks like this is nearly unreadable for someone unfamiliar:
function App() {
return <Foo>
<Bar>
<Baz>
<div id="deep-div">
Too deeply nested!
</div>
</Baz>
</Bar>
</Foo>
}
Bad Practice
function FormContainer() {
// This JSX tree is too deep
return <FormWrapper>
<Form>
<FormEntry>
<Label>
<strong>Name</strong>
</Label>
<FormInput type="text" / >
</FormEntry>
</Form>
</FormWrapper>
}
Recommended
function FormContainer() {
// the FormEntry component has been modified to accept the labelName and inputType.
// It now returns JSX that contains a label and a field.
return <FormWrapper>
<Form>
<FormEntry labelName="Name" inputType="text">
</FormEntry>
</Form>
</FormWrapper>
}