How to get the ObjectInfo in LWC

How to get info about the object using getObjectInfo in LWC.

When we are working with Lightning Web Components, we might comes across a business requirement where need some info about the object.

When I say Info am referring to metadata describing the object’s fields, child relationships, record type, and theme.

Don't try to invoke an Apex method use Describe class and get the required info. Make use of out of the box available feature.

In that case, we can make use of one of the named imports that we get access to out of the box and that is getObjectInfo

Let me show you a snippet using getObjectInfo

import { LightningElement, wire } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';

export default class Example extends LightningElement {
    @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
    accountObject({error, data}){
        if(data){
            console.log(data);
        }else{
            console.log(error);
        }
    }
}

Hope this is helpful!