1e41f4b71Sopenharmony_ci# xcomponent
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci> **NOTE**
4e41f4b71Sopenharmony_ci> 
5e41f4b71Sopenharmony_ci> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciThe **\<xcomponent>** displays the components to which the EGL/OpenGLES or media data is written.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## Required Permissions
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ciNone
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## Child Components
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ciNot supported
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## Attributes
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciIn addition to the [universal attributes](js-components-common-attributes.md), the following attributes are supported.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci| Name         | Type  | Mandatory  | Description                                      |
22e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | ---------------------------------------- |
23e41f4b71Sopenharmony_ci| id          | string | Yes   | Unique ID of the component. The value can contain a maximum of 128 characters.                  |
24e41f4b71Sopenharmony_ci| type        | string | Yes   | Type of the component. The options are as follows:<br>- **surface**: The content of this type of component is displayed individually, without being combined with that of other components.<br>- **component**: The content of this type of component is displayed after having been combined with that of other components.<br>|
25e41f4b71Sopenharmony_ci| libraryname | string | No   | Name of the dynamic library generated after compilation at the application native layer.                     |
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci## Styles
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ciThe [universal styles](js-components-common-styles.md) are supported.
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci## Events
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ciIn addition to the [universal events](js-components-common-events.md), the following events are supported.
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci| Name                              | Description                                    |
36e41f4b71Sopenharmony_ci| -------------------------------- | ---------------------------------------- |
37e41f4b71Sopenharmony_ci| onLoad(context?: object) => void | Triggered when the plug-in is loaded.<br>**context**: context of an **\<XComponent>** object. The APIs contained in the context are defined by developers.|
38e41f4b71Sopenharmony_ci| onDestroy() => void              | Triggered when the plug-in is destroyed.                            |
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci## Methods
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ciIn addition to the [universal methods](js-components-common-methods.md), the following methods are supported.
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci| Name                      | Parameter                                      | Return Value Type | Description                                      |
45e41f4b71Sopenharmony_ci| ------------------------ | ---------------------------------------- | ------ | ---------------------------------------- |
46e41f4b71Sopenharmony_ci| getXComponentSurfaceId   | -                                        | string | Obtains the ID of the surface held by the **\<XComponent>**. The ID can be used for @ohos interfaces, such as camera-related interfaces.|
47e41f4b71Sopenharmony_ci| setXComponentSurfaceSize | {<br>surfaceWidth: number,<br>surfaceHeight: number  <br>} | -      | Sets the width and height of the surface held by the **\<XComponent>**.            |
48e41f4b71Sopenharmony_ci| getXComponentContext     | -                                        | object | Obtains the instance object of the xcomponent method extended by the developer.              |
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci## Example
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ciProvide a surface-type **\<XComponent>** to support camera preview and other capabilities.
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci   ```html
55e41f4b71Sopenharmony_ci<!-- xxx.hml -->
56e41f4b71Sopenharmony_ci<div style="height: 500px; width: 500px; flex-direction: column; justify-content: center; align-items: center;">
57e41f4b71Sopenharmony_ci	<text id = 'camera' class = 'title'>camera_display</text>
58e41f4b71Sopenharmony_ci	<xcomponent id = 'xcomponent' type = 'surface' onload = 'onload' ondestroy = 'ondestroy'></xcomponent>
59e41f4b71Sopenharmony_ci</div>
60e41f4b71Sopenharmony_ci   ```
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci   ```js
63e41f4b71Sopenharmony_ci// xxx.js
64e41f4b71Sopenharmony_ciimport camera from '@ohos.multimedia.camera';
65e41f4b71Sopenharmony_ciexport default {
66e41f4b71Sopenharmony_ci    onload() {
67e41f4b71Sopenharmony_ci        var surfaceId = this.$element('xcomponent').getXComponentSurfaceId();
68e41f4b71Sopenharmony_ci        camera.createPreviewOutput(surfaceId).then((previewOutput) => {
69e41f4b71Sopenharmony_ci            console.log('Promise returned with the PreviewOutput instance');
70e41f4b71Sopenharmony_ci        })
71e41f4b71Sopenharmony_ci    }
72e41f4b71Sopenharmony_ci}
73e41f4b71Sopenharmony_ci   ```
74