본문 바로가기
오류노트

Uncaught Error: ErrorComponent(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.

by 어컴띵 2021. 3. 16.

리액트에서 다음과 같은 오류가 날때

Uncaught Error: ErrorComponent(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.

 

function ErrorComponent({show,setError,message,type}){
    const [close, setClose] = useState(show);
    useEffect(()=>{
        setClose(show)
    },[show])

    const handleClose = () => {
        setClose(false);
        setError(false);
        return 0;
    }

    const errorModal = {
        server:<ServerErrorModal close={close} handleClose={handleClose} message={message} ></ServerErrorModal>,
        login:<LoginErrorModal close={close} handleClose={handleClose} message={message} ></LoginErrorModal>
    }

    const modal = errorModal[type];

    return (
    	modal
    )
}
export default ErrorComponent;

 

 

return 문에 태그를 추가하면 오류가 나지 않는다.

    return (
        <>
            {modal}
        </>
    )