--- sidebar_position: 5 title: Component subcomponent --- Our component will mainly call for an item, whether to fill the grid, display the boxes of the recipe and even the result. In order not to have to repeat code in our component, we will therefore create a sub-component which will allow the display of our elements. Our component remains simple but uses the Drag & Drop method. ## Creating our base component view ```cshtml title="Components/CraftingItem.razor"
// highlight-next-line Update heading
@code { private string currentHeading = "Initial heading"; private string? newHeading; private string checkedMessage = "Not changed yet"; // highlight-start private void UpdateHeading() { currentHeading = $"{newHeading}!!!"; } private void CheckChanged() { checkedMessage = $"Last changed at {DateTime.Now}"; } // highlight-end } ``` In the following example, `UpdateHeading`: * Is called asynchronously when the button is selected. * Waits two seconds before updating the heading. ```cshtml title="Pages/EventHandlerExample2.razor" @page "/event-handler-example-2"
// highlight-next-line
@code { private string currentHeading = "Initial heading"; private string? newHeading; // highlight-start private async Task UpdateHeading() { await Task.Delay(2000); currentHeading = $"{newHeading}!!!"; } // highlight-end } ``` ### Event arguments For events that support an event argument type, specifying an event parameter in the event method definition is only necessary if the event type is used in the method. In the following example, `MouseEventArgs` is used in the `ReportPointerLocation` method to set message text that reports the mouse coordinates when the user selects a button in the UI. ```cshtml title="Pages/EventHandlerExample3.razor" @page "/event-handler-example-3" @for (var i = 0; i < 4; i++) {}
@mousePointerMessage
@code { private string? mousePointerMessage; // highlight-start private void ReportPointerLocation(MouseEventArgs e) { mousePointerMessage = $"Mouse coordinates: {e.ScreenX}:{e.ScreenY}"; } // highlight-end } ``` ### Supported EventArgs | Event | Class | Document Object Model (DOM) events | | ---- | ---- | ---- | | Clipboard | ClipboardEventArgs | `oncut`, `oncopy`, `onpaste` | | Drag | DragEventArgs | `ondrag`, `ondragstart`, `ondragenter`, `ondragleave`, `ondragover`, `ondrop`, `ondragend` | | Error | ErrorEventArgs | `onerror` | | General | EventArgs | `onactivate`, `onbeforeactivate`, `onbeforedeactivate`, `ondeactivate`, `onfullscreenchange`, `onfullscreenerror`, `onloadeddata`, `onloadedmetadata`, `onpointerlockchange`, `onpointerlockerror`, `onreadystatechange`, `onscroll` | | Clipboard | EventArgs | `onbeforecut`, `onbeforecopy`, `onbeforepaste` | | Input | EventArgs | `oninvalid`, `onreset`, `onselect`, `onselectionchange`, `onselectstart`, `onsubmit` | | Media | EventArgs | `oncanplay`, `oncanplaythrough`, `oncuechange`, `ondurationchange`, `onemptied`, `onended`, `onpause`, `onplay`, `onplaying`, `onratechange`, `onseeked`, `onseeking`, `onstalled`, `onstop`, `onsuspend`, `ontimeupdate`, `ontoggle`, `onvolumechange`, `onwaiting` | | Focus | FocusEventArgs | `onfocus`, `onblur`, `onfocusin`, `onfocusout` | | Input | ChangeEventArgs | `onchange`, `oninput` | | Keyboard | KeyboardEventArgs | `onkeydown`, `onkeypress`, `onkeyup` | | Mouse | MouseEventArgs | `onclick`, `oncontextmenu`, `ondblclick`, `onmousedown`, `onmouseup`, `onmouseover`, `onmousemove`, `onmouseout` | | Mouse pointer | PointerEventArgs | `onpointerdown`, `onpointerup`, `onpointercancel`, `onpointermove`, `onpointerover`, `onpointerout`, `onpointerenter`, `onpointerleave`, `ongotpointercapture`, `onlostpointercapture` | | Mouse wheel | WheelEventArgs | `onwheel`, `onmousewheel` | | Progress | ProgressEventArgs | `onabort`, `onload`, `onloadend`, `onloadstart`, `onprogress`, `ontimeout` | | Touch | TouchEventArgs | `ontouchstart`, `ontouchend`, `ontouchmove`, `ontouchenter`, `ontouchleave`, `ontouchcancel` |