Minified React error #152 - how to resolve this?

In case it helps someone, I resolved this problem by returning null instead of false (my function is wrapped inside an HOC)

Edit: sometimes I did not want to render anything. In such case, I returned false in the render method as something like this:

    render(){
        return condition && <ThingsIWantToDisplay/>; //condition is a boolean
    }

The component class is then wrapped within an HOC (to provide React Context) like this:

export default HOC(Component);

 

When condition is false, an error occurs in the production build.

Changing the render function as shown below alleviated the problem:

    render(){
        return condition?<ThingsIWantToDisplay/>:null; //condition is a boolean
    }

Remove any comment inside render/ return method

I used this regex in VSCode to find the troublesome comments: (\s*\n?\s*//

enter image description here

More help here


The error description is here, you return nothing as result of rendermethod of you react component. Return something else instead of it.


I have the same issue check your useState import

import { useState } from 'react/cjs/react.production.min'; change into import react,{usestate} from 'react'

Tags:

Reactjs