Skip to content

Commit

Permalink
Update getContext() usage examples with namespace argument in Interac…
Browse files Browse the repository at this point in the history
…tivity API Documentation (#63411)

Co-authored-by: dhananjaykuber <dhananjaykuber@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
Co-authored-by: juanmaguitar <juanmaguitar@git.wordpress.org>
  • Loading branch information
4 people authored Jul 11, 2024
1 parent 32ec81b commit 0b54ea4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion docs/reference-guides/interactivity-api/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,12 @@ Apart from the store function, there are also some methods that allows the devel

#### getContext()

Retrieves the context inherited by the element evaluating a function from the store. The returned value depends on the element and the namespace where the function calling `getContext()` exists.
Retrieves the context inherited by the element evaluating a function from the store. The returned value depends on the element and the namespace where the function calling `getContext()` exists. It can also take an optional namespace argument to retrieve the context of a specific interactive region.

```js
const context = getContext('namespace');
```
- `namespace` (optional): A string that matches the namespace of an interactive region. If not provided, it retrieves the context of the current interactive region.

```php
// render.php
Expand All @@ -1073,6 +1078,11 @@ store( "myPlugin", {
const context = getContext();
// Logs "false"
console.log('context => ', context.isOpen)

// With namespace argument.
const myPluginContext = getContext("myPlugin");
// Logs "false"
console.log('myPlugin isOpen => ', myPluginContext.isOpen);
},
},
});
Expand Down

0 comments on commit 0b54ea4

Please sign in to comment.