+ Start a Discussion
Phuc Nguyen 18Phuc Nguyen 18 

LWC pass wire value to the connectedCallback

Hello All,
I am trying to pass a value from @wire to the connectedCallback
 
import PRICE_FIELD from '@salesforce/schema/Order__c.Price__c';
 
@wire(getRecord, { recordId: '$recordId', fields: [PRICE_FIELD] })
  record;
I tried this within the connectedcallback but no value
this.priceId = this.record.data ? getFieldValue(this.record.data, PRICE_FIELD) : '';

So process flow is 
  1. @wire
  2. callback
  3. @wire

So at step 3 the @wire gets a value but not a step 1
What am I doing wrong?

Thank you,
P
 
Best Answer chosen by Phuc Nguyen 18
Piyush jadavPiyush jadav

Create one container div inside template tag and add attributes lwc:dom="manual" in your html file

<template> <div class="container" lwc:dom="manual"></div> </template>

All Answers

Piyush jadavPiyush jadav

Hi

Connected call back is alway run before component is initialized.

if u want to get value in connectedcallback then u have to call getRecord inside connectedcallback like belove

connectedcallback(){
      getRecord({ recordId: '$recordId', fields: [PRICE_FIELD] })
    .then(result => {
        console.log({result})
    })
    .catch(err => { console.log({err})});

}

Phuc Nguyen 18Phuc Nguyen 18
Thank you for the reply Piyush.  I tried implementing your suggesiton but I am getting this error:
 "[LWC error]: The `appendChild` method is available only on elements that use the `lwc:dom=\"manual\"` directive."
ANy thoughts on the error message?
Thank you,
P
 
Piyush jadavPiyush jadav

Create one container div inside template tag and add attributes lwc:dom="manual" in your html file

<template> <div class="container" lwc:dom="manual"></div> </template>

This was selected as the best answer