Services
The container library enables seamless two-way communication between parent and child components, without relying on props. This makes it a powerful tool in your arsenal.
Set and Get
// 1. Set a regular value (string/number)
services.set("myContainerName1", "Hello World 1");
console.log(services.get("myContainerName1"));
// Result: Hello World 1
// 2. Set an object
services.set("myContainerName2", {
title: "Hello World 2",
description: "Lorem ipsum dolor",
});
console.log(services.get("myContainerName2").title);
// Result: Hello World 2
// 3. Set a function
services.set("myContainerName3", function(arg1, arg2) {
console.log(`Hello ${arg1} ${arg2}`);
});
// Pass the expected arguments to the function after the first argument
// When get is called, the function is automatically triggered
services.get("myContainerName3", "World!", 3);
// Result: Hello World!Has and Overwrite
Has
Overwrite
Example
What's the Point?
Last updated