getting maximum update depth exceeded error when trying to conditional render a section inside render.
I have a component in which i need to render sections like below
<code> renderSections() {
switch(sectionId) {
case section1:
return <section1 />
case section2:
return <section2 />
default:
}
}
render(){
this.renderSections();
}
}
export const mapStateToProps = (state, props) => {
return {
renderSection2: formValueSelector(props.formName)(state, 'a'),
array1: array1 || []
}
}```
I need to render section2 only when renderSection2 is true and array1 length === 1.
I tried to do something like below.
case section2:
if(renderSection2 && array1.length === 1) {
return <section2 />
}
return null;
But, Im getting maximum update depth exceeded error. Couldn't figure out what's causing the issue. Can someone help on How to solve the issue ?
I cannot change the switch statement to if else's as I have many cases in switch. any insights will be helpful. ThankYou
</code>
<code> renderSections() {
switch(sectionId) {
case section1:
return <section1 />
case section2:
return <section2 />
default:
}
}
render(){
this.renderSections();
}
}
export const mapStateToProps = (state, props) => {
return {
renderSection2: formValueSelector(props.formName)(state, 'a'),
array1: array1 || []
}
}```
I need to render section2 only when renderSection2 is true and array1 length === 1.
I tried to do something like below.
case section2:
if(renderSection2 && array1.length === 1) {
return <section2 />
}
return null;
But, Im getting maximum update depth exceeded error. Couldn't figure out what's causing the issue. Can someone help on How to solve the issue ?
I cannot change the switch statement to if else's as I have many cases in switch. any insights will be helpful. ThankYou
</code>
renderSections() {
switch(sectionId) {
case section1:
return <section1 />
case section2:
return <section2 />
default:
}
}
render(){
this.renderSections();
}
}
export const mapStateToProps = (state, props) => {
return {
renderSection2: formValueSelector(props.formName)(state, 'a'),
array1: array1 || []
}
}```
I need to render section2 only when renderSection2 is true and array1 length === 1.
I tried to do something like below.
case section2:
if(renderSection2 && array1.length === 1) {
return <section2 />
}
return null;
But, Im getting maximum update depth exceeded error. Couldn't figure out what's causing the issue. Can someone help on How to solve the issue ?
I cannot change the switch statement to if else's as I have many cases in switch. any insights will be helpful. ThankYou