DEV Community 👩‍💻👨‍💻

Zen
Zen

Posted on

Cara Antar Komponen HTML Berinteraksi Tanpa Framework JavaScript

Jadi, di sini kita menggunakan localStorage. Caranya seperti ini:

Pada setter:

localStorage.nama = "Zen";
dispatchEvent(new Event("storage"));
Enter fullscreen mode Exit fullscreen mode

Kemudian, pada getter:

addEventListener("storage", (x) => {
  if (x.key == "nama") {
    console.log(`Namanya adalah ${localStorage.nama}`);
  }
});
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Become a Moderator Do you want us to help make DEV a better place?

Fill out this survey and help us by becoming a tag moderator here at DEV.