+ Start a Discussion
Sergio Mac IntoshSergio Mac Intosh 

LWC Wire Method on 1 Parameter

Hi All,

I have a Wired Method like this:
 
recordId = '';
searchString;

@wire(searchUsers, {recordId: '$recordId', searchString: '$searchString'})

The method is working correctly, but the method is running everytime the recordId or the searchstring is changed. I would only like to run it when the searchstring is being changed & also not onload of the component. How can i manage this?

 
B KarthickeyanB Karthickeyan
searchString(){
searchUser({recordId: this.recordId, searchString:this.searchString}).then(result => {
            this.error = undefined;
            if(this.message !== undefined  ) {
               // Data returned from the apex method will be available here
               this.recordId=this.message;
            }

        })
        .catch(error => {
            this.message = undefined;
            this.error = error;
            // eslint-disable-next-line no-console
            console.log("error ", JSON.stringify(this.error));
        });
}

Instead of using the wire method you can the method as mentioned below. you can write the following code inside the js Function.
Hope it helps you!