Search code examples
javascriptjsonreactjs

importing an object within an object from an API


I have a user JSON file and within the address object theres a geo object that I tried importing using this method:

{identity.address && identity.geo && (
            <div>
              <b>Lat: </b> {identity.address.geo.lat}
            </div>
            )}

Which render nothing on the webpage.


Solution

  • When importing an object within an object I believe you have to reference the parent first. So

    identity.geo

    should instead be

    identity.address.geo