Store and Retrieve Region

In this document, you'll learn how to store a customer's region's ID and retrieve the selected region.

Store Selected Region ID#

When the customer selects their region, for example, from a dropdown, store that region's ID in the localStorage.

For example:

Code
localStorage.setItem("region_id", region.id)

Then, you retrieve it later using the localSorage.getItem method later:

Code
const regionId = localStorage.getItem("region_id")

Retrieve Selected Region#

To retrieve the selected region, use the Retrieve Region API route:

Code
1const regionId = localStorage.getItem("region_id")2
3fetch(`http://localhost:9000/store/regions/${regionId}`, {4  credentials: "include",5  headers: {6    "x-publishable-api-key": process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY || "temp",7  },8})9.then((res) => res.json())10.then(({ region }) => {11  // do something with region.12  console.log(region)13})
Was this page helpful?
Edit this page
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break