Magento 2 – How to get customer data in custom js?

Magento 2 - How to get customer data in custom js?

Hello Devs, In this tutorial we are going to see how we can get customer data in a custom js component.

We can get customer data by injecting “Magento_Customer/js/customer-data” using require function in our custom js/javascript component in Magento 2.

After injecting the object, we can use customerData.get(‘customer’) to get customer information if the customer is logged in.

Let’s see and understand it using the below example.

You may also like:

How to use jQuery in Magento 2?

That’s it for this tutorial, I will see you in the next tutorial. Happy Coding 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *