Expected the depth of nested jsx elements to be <= 2, but found 3
106 this.handleOptionDeSelect(option);
107 }}
108 />
109 <InputTextBox110 data-test="custom-select-input-box"111 inputValue={searchKeyword}112 placeholder={defaultText}113 handleOnChange={(e) => {114 this.handleSearchText(e);115 }}116 handleOnFocus={(e) => {117 this.handleFocusOnSelect(e);118 }}119 />120 </div>
121 {showOption && (
122 <SelectOptionList
Expected the depth of nested jsx elements to be <= 2, but found 3
99 className="tag-ctn tag-ctn-bootstrap-focus"
100 >
101 <div className="tag-sel-ctn">
102 <Tag103 data-test="customSelect-tag"104 tagList={selectedOption}105 handleTagRemove={(option) => {106 this.handleOptionDeSelect(option);107 }}108 />109 <InputTextBox
110 data-test="custom-select-input-box"
111 inputValue={searchKeyword}
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>
}