diff --git a/docs/reference-guides/interactivity-api/api-reference.md b/docs/reference-guides/interactivity-api/api-reference.md index acfba8c48af665..8306adec9521c8 100644 --- a/docs/reference-guides/interactivity-api/api-reference.md +++ b/docs/reference-guides/interactivity-api/api-reference.md @@ -1078,6 +1078,33 @@ store( "myPlugin", { }); ``` +When `getContext()` called with a namespace argument, `getContext(namespace)` retrieves the context specific to that namespace within the current element's context. + +```php +// render.php +
+ +
+``` + +```js +// store +import { store, getContext } from '@wordpress/interactivity'; + +store( "myPlugin", { + actions: { + log: () => { + // Retrieve the context for the 'region' namespace. + const regionContext = getContext('region'); + // Logs "North" + console.log('regionContext => ', regionContext.name); + // Logs the entire 'region' context object. + console.log('regionContext => ', regionContext); + }, + }, +}); +``` + #### getElement() Retrieves a representation of the element that the action is bound to or called from. Such representation is read-only, and contains a reference to the DOM element, its props and a local reactive state.