Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead

After the user registers, I want to show his email on another page. In the true case, I have it as I want but in the false case, it shows an error. I will put that error below. Please help me fix this

**My activation page**

import React from "react";
import "./auth.css";

const Activation = (props) => {
  const email = (props.location && props.location.state) || {};

  return (
    <>
      {email ? (
        <div className="activation">
          <i className="vjtal06 fas fa-check-circle"></i>
          <h2>Registration successful.</h2>
          <div className="abn5uhi">
            <p>Thank you. We have send you email to {email}</p>
            <p>
              Pleace click the link in that message to activate your account.
            </p>
          </div>
        </div>
      ) : (
        <div className="activation">
          <i className="vjtal06 fas fa-check-circle"></i>
          <h2>Session Expired</h2>
          <div className="abn5uhi">
            <p>Pleace try again.</p>
          </div>
        </div>
      )}
    </>
  );
};

export default Activation;

Please click here to show my error img

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

All you need to do is remove this || {}; part 🙂

Explaination:
There is something in javascript called Truthy and Falsy values and this means what can be translated into true and false if you checked them,
in your case {} is Truthy value, so, in case of empty email, it still gets converted as true boolean value

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading