There is a condition for setState

if (containerWidth <= 719) { this.setState({ displayed: 1 }); } else { this.setState({ displayed: 3 }); } 

need to write it in this form

 condition ? value_if_condition_true : value_if_condition_false; 

there must be something like this

 this.setState({isMobile: containerWidth <= 700}); 

just in this example, in contrast to the question, the isMobile state can be true or false, and the question in the number state

    1 answer 1

     this.setState({ displayed: containerWidth <= 719 ? 1 : 3 });