function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vinni shreevinni shree 

Hi I'm new to dev

Can someone please explain me when we use connected callback and wire methoda with small use case scenario, I know the defintiions of both but unable to use those at the right time.

 

Thank you 

Best Answer chosen by vinni shree
AnkaiahAnkaiah (Salesforce Developers) 
Hi Vinni,

connectedCallback() in Lightning Web Component flows from parent to child. For Example if we have a parent and child component, connectedCallback() defined in parent component will get fire first then child component.
We can’t access child elements from the callbacks because they don’t exist yet.
It’s invoked after constructor hook fired.
If we want fire any logic on component load then we should use ConnectedCallBack() life cycle hook.

Refer the below links.
https://salesforcegirl.in/2021/06/14/connectedcallback-in-lwclightning-web-component/#:~:text=It's%20invoked%20after%20constructor%20hook,ConnectedCallBack()%20life%20cycle%20hook.

https://salesforce.stackexchange.com/questions/313806/connectedcallback-vs-renderedcallback-in-lightning-web-component

If this helps, Please mark it as best answer.

Thanks!!

All Answers

AnkaiahAnkaiah (Salesforce Developers) 
Hi Vinni,

connectedCallback() in Lightning Web Component flows from parent to child. For Example if we have a parent and child component, connectedCallback() defined in parent component will get fire first then child component.
We can’t access child elements from the callbacks because they don’t exist yet.
It’s invoked after constructor hook fired.
If we want fire any logic on component load then we should use ConnectedCallBack() life cycle hook.

Refer the below links.
https://salesforcegirl.in/2021/06/14/connectedcallback-in-lwclightning-web-component/#:~:text=It's%20invoked%20after%20constructor%20hook,ConnectedCallBack()%20life%20cycle%20hook.

https://salesforce.stackexchange.com/questions/313806/connectedcallback-vs-renderedcallback-in-lightning-web-component

If this helps, Please mark it as best answer.

Thanks!!
This was selected as the best answer
vinni shreevinni shree
Thank you Ankaiah I understood.