Tuesday, 19 December 2023

What is @Wire Service?

 What is @Wire Service?

1) Wire Service is build on Lightning Data Service

2) LWC component use @wire in their JavaScript class to read 

   data from one of the wire adapters in the lightning/ui*Api

3) @Wire is a reactive service.

4) The wire adapter defines the data shape that the wire service 

   provisions in an immutable stream

Syntax

import {adapterId} from 'adaptermodel'

@wire(adapterId, adapterconfig)

propertyorfuncation;

@wire service and feach user Details

import {lightningElement } from 'lwc';

import {getRecord} from 'lightning/ui';

import id from '@salesforce/user/id';

import NAME_FIELD from '@salesforce/schema/User.Name;

import EMAIL_FIELD from '@salesforce/schema/User.EMAIL;

const fields = [NAME_FIELD, EMAIL_FIELD];

export default class WireDemo extends LightningElement {

  userId = id

  @wire(getRecord,{recordId:'userId', fields:fields})

  this is one way get data write it 

 Feach Data Value 

----------------------------------------

  userdetailHandler(response){

     let data = response.data

let error = response.error

  }

  --------------------------------------

  userDetail

  // Function 

  userdetailHandler({data, error}){

    if(data){

console.data(data)

this.userDetail = data.fields

}

if(error){

console.error(error)

}

  }

  @wire(getRecord,{recordId:'userId', fields:fields})

    // Property

  userdetailPropery;

}

No comments:

Post a Comment