How to avoid error Cannot read property of undefined using LWC Wired properties but to display two properties? afterRender threw an error in 'c:tryc' [Cannot read property 'x' of undefined]
HTML file of tryc.html
<template>
x.data {x.data}<br/>
y.data {y.data}<br/>
x.data.x {x.data.x}<br/>
y.data.y {y.data.y}<br/>
</template>
Listing of Tryc.js
import { LightningElement, wire, api } from 'lwc';
import getX from '@salesforce/apex/TryCont.getX';
import getY from '@salesforce/apex/TryCont.getY';
export default class Tryc extends LightningElement {
@wire(getX)
x
@wire(getY)
y
}
Apex Controller
public with sharing class TryCont {
@AuraEnabled(Cacheable=true)
public static Map<String, Object> getX() {
return new Map<String, Object>{'x'=>'y'};
}
@AuraEnabled(Cacheable=true)
public static Map<String, Object> getY() {
return new Map<String, Object>{'y'=>'x'};
}
}