பொதுவான components (எ.கா. <div>)
<div> போன்ற எல்லா built-in browser components-உம் சில பொதுவான props மற்றும் events-ஐ support செய்கின்றன.
- Reference
- பொதுவான components (எ.கா.
<div>) refcallback function- React event object
AnimationEventhandler functionClipboardEventhandler functionCompositionEventhandler functionDragEventhandler functionFocusEventhandler functionEventhandler functionInputEventhandler functionKeyboardEventhandler functionMouseEventhandler functionPointerEventhandler functionTouchEventhandler functionTransitionEventhandler functionUIEventhandler functionWheelEventhandler function
- பொதுவான components (எ.கா.
- Usage
Reference
பொதுவான components (எ.கா. <div>)
<div className="wrapper">சில உள்ளடக்கம்</div>மேலும் examples-ஐ கீழே பார்க்கவும்.
Props
இந்த சிறப்பு React props எல்லா built-in components-க்கும் support செய்யப்படுகின்றன:
-
children: ஒரு React node (element, string, number, portal,null,undefinedமற்றும் booleans போன்ற empty node, அல்லது பிற React nodes-ன் array). Component-க்குள் உள்ள content-ஐ குறிப்பிடுகிறது. JSX பயன்படுத்தும்போது, பொதுவாக<div><span /></div>போன்ற nested tags மூலம்childrenprop-ஐ மறைமுகமாக குறிப்பிடுவீர்கள். -
dangerouslySetInnerHTML: உள்ளே raw HTML string கொண்ட{ __html: '<p>some html</p>' }வடிவ object. DOM node-ன்innerHTMLproperty-ஐ override செய்து, pass செய்யப்பட்ட HTML-ஐ உள்ளே காட்டுகிறது. இதை மிகுந்த கவனத்துடன் மட்டுமே பயன்படுத்த வேண்டும்! உள்ளிருக்கும் HTML நம்பத்தகுந்ததல்ல என்றால் (உதாரணமாக, அது user data அடிப்படையாக இருந்தால்), XSS vulnerability சேர்க்கும் அபாயம் உண்டு.dangerouslySetInnerHTMLபயன்படுத்துவது பற்றி மேலும் வாசிக்கவும். -
ref:useRefஅல்லதுcreateRef-இலிருந்து கிடைக்கும் ref object,refcallback function, அல்லது legacy refs-க்கான string. இந்த node-க்கான DOM element உங்கள் ref-இல் நிரப்பப்படும். Refs மூலம் DOM-ஐ கையாளுவது பற்றி மேலும் வாசிக்கவும். -
suppressContentEditableWarning: ஒரு boolean.trueஎன்றால்,childrenமற்றும்contentEditable={true}இரண்டும் கொண்ட elements-க்கு React காட்டும் warning-ஐ suppress செய்கிறது (இவை பொதுவாக ஒன்றாகச் சரியாக வேலை செய்யாது).contentEditablecontent-ஐ கையால் நிர்வகிக்கும் text input library உருவாக்கினால் இதைப் பயன்படுத்துங்கள். -
suppressHydrationWarning: ஒரு boolean. நீங்கள் server rendering பயன்படுத்தினால், server மற்றும் client வேறு content render செய்யும்போது பொதுவாக warning வரும். சில அரிய சந்தர்ப்பங்களில் (timestamps போன்றவை), exact match-ஐ உறுதி செய்வது மிகவும் கடினமாகவோ சாத்தியமற்றதாகவோ இருக்கும்.suppressHydrationWarning-ஐtrueஆக set செய்தால், அந்த element-ன் attributes மற்றும் content-இல் உள்ள mismatches குறித்து React warning காட்டாது. இது ஒரு level ஆழம் மட்டுமே வேலை செய்யும்; escape hatch ஆகப் பயன்படுத்துவதற்கானது. இதை மிகையாகப் பயன்படுத்த வேண்டாம். Hydration errors-ஐ suppress செய்வது பற்றி வாசிக்கவும். -
style: CSS styles கொண்ட object, உதாரணமாக{ fontWeight: 'bold', margin: 20 }. DOMstyleproperty போலவே, CSS property பெயர்கள்font-weightஎன்பதற்குப் பதிலாகfontWeightபோன்றcamelCaseவடிவில் எழுதப்பட வேண்டும். Values ஆக strings அல்லது numbers pass செய்யலாம்.width: 100போன்ற number pass செய்தால், அது unitless property அல்லாத வரை React value-க்கு தானாகpx(“pixels”) சேர்க்கும். Style values முன்கூட்டியே தெரியாத dynamic styles-க்கு மட்டும்styleபயன்படுத்த பரிந்துரைக்கிறோம். மற்ற சந்தர்ப்பங்களில்,classNameமூலம் plain CSS classes பயன்படுத்துவது அதிக திறனானது.classNameமற்றும்styleபற்றி மேலும் வாசிக்கவும்.
இந்த standard DOM props-உம் எல்லா built-in components-க்கும் support செய்யப்படுகின்றன:
accessKey: ஒரு string. Element-க்கான keyboard shortcut-ஐ குறிப்பிடுகிறது. பொதுவாக பரிந்துரைக்கப்படாது.aria-*: ARIA attributes இந்த element-க்கான accessibility tree தகவலை குறிப்பிட அனுமதிக்கின்றன. முழு reference-க்கு ARIA attributes பார்க்கவும். React-இல், எல்லா ARIA attribute பெயர்களும் HTML-இல் இருப்பதுபோலவே இருக்கும்.autoCapitalize: ஒரு string. User input capitalized ஆக வேண்டுமா, எப்படி ஆக வேண்டும் என்பதை குறிப்பிடுகிறது.className: ஒரு string. Element-ன் CSS class name-ஐ குறிப்பிடுகிறது. CSS styles பயன்படுத்துவது பற்றி மேலும் வாசிக்கவும்.contentEditable: ஒரு boolean.trueஎன்றால், rendered element-ஐ user நேரடியாக edit செய்ய browser அனுமதிக்கும். Lexical போன்ற rich text input libraries உருவாக்க இதைப் பயன்படுத்துகிறார்கள்.contentEditable={true}கொண்ட element-க்கு React children pass செய்ய முயன்றால் React warning காட்டும்; user edits-க்குப் பிறகு அதன் content-ஐ React update செய்ய முடியாது.data-*: Data attributes மூலம் element-க்கு சில string data attach செய்யலாம், உதாரணமாகdata-fruit="banana". React-இல் இவை பொதுவாக பயன்படுத்தப்படாது, ஏனெனில் data-வை props அல்லது state-இலிருந்து வாசிப்பதே வழக்கம்.dir:'ltr'அல்லது'rtl'. Element-ன் text direction-ஐ குறிப்பிடுகிறது.draggable: ஒரு boolean. Element draggable ஆக இருக்க வேண்டுமா என்பதை குறிப்பிடுகிறது. HTML Drag and Drop API-ன் ஒரு பகுதி.enterKeyHint: ஒரு string. Virtual keyboards-இல் enter key-க்கு எந்த action காட்ட வேண்டும் என்பதை குறிப்பிடுகிறது.htmlFor: ஒரு string.<label>மற்றும்<output>-க்கு, label-ஐ ஒரு control-உடன் இணைக்க அனுமதிக்கிறது. இதுforHTML attribute-க்கு சமம். React HTML attribute பெயர்களுக்குப் பதிலாக standard DOM property names (htmlFor) பயன்படுத்துகிறது.hidden: ஒரு boolean அல்லது string. Element hidden ஆக இருக்க வேண்டுமா என்பதை குறிப்பிடுகிறது.id: ஒரு string. இந்த element-க்கான unique identifier-ஐ குறிப்பிடுகிறது; பின்னர் அதை கண்டுபிடிக்க அல்லது பிற elements-உடன் இணைக்க இதைப் பயன்படுத்தலாம். ஒரே component-ன் பல instances இடையே conflicts தவிர்க்கuseIdமூலம் உருவாக்குங்கள்.is: ஒரு string. குறிப்பிடப்பட்டால், component ஒரு custom element போல நடக்கும்.inputMode: ஒரு string. எந்த வகை keyboard காட்ட வேண்டும் என்பதை குறிப்பிடுகிறது (உதாரணமாக text, number, அல்லது telephone).itemProp: ஒரு string. Structured data crawlers-க்கு element எந்த property-யை represent செய்கிறது என்பதை குறிப்பிடுகிறது.lang: ஒரு string. Element-ன் மொழியை குறிப்பிடுகிறது.onAnimationEnd: ஒருAnimationEventhandler function. CSS animation முடிந்தபோது fire ஆகும்.onAnimationEndCapture: capture phase-இல் fire ஆகும்onAnimationEnd-ன் version.onAnimationIteration: ஒருAnimationEventhandler function. CSS animation-ன் ஒரு iteration முடிந்து மற்றொன்று தொடங்கும்போது fire ஆகும்.onAnimationIterationCapture: capture phase-இல் fire ஆகும்onAnimationIteration-ன் version.onAnimationStart: ஒருAnimationEventhandler function. CSS animation தொடங்கும்போது fire ஆகும்.onAnimationStartCapture: capture phase-இல் fire ஆகும்onAnimationStart.onAuxClick: ஒருMouseEventhandler function. Primary அல்லாத pointer button click செய்யப்படும் போது fire ஆகும்.onAuxClickCapture: capture phase-இல் fire ஆகும்onAuxClick-ன் version.onBeforeInput: ஒருInputEventhandler function. Editable element-ன் value மாற்றப்படுவதற்கு முன் fire ஆகும். React இன்னும் nativebeforeinputevent-ஐ பயன்படுத்தவில்லை; அதற்கு பதிலாக பிற events மூலம் polyfill செய்ய முயல்கிறது.onBeforeInputCapture: capture phase-இல் fire ஆகும்onBeforeInput-ன் version.onBlur: ஒருFocusEventhandler function. Element focus இழக்கும்போது fire ஆகும். Built-in browserblurevent போல அல்லாமல், React-இல்onBlurevent bubbles ஆகும்.onBlurCapture: capture phase-இல் fire ஆகும்onBlur-ன் version.onClick: ஒருMouseEventhandler function. Pointing device-இல் primary button click செய்யப்படும் போது fire ஆகும்.onClickCapture: capture phase-இல் fire ஆகும்onClick-ன் version.onCompositionStart: ஒருCompositionEventhandler function. Input method editor புதிய composition session தொடங்கும்போது fire ஆகும்.onCompositionStartCapture: capture phase-இல் fire ஆகும்onCompositionStart-ன் version.onCompositionEnd: ஒருCompositionEventhandler function. Input method editor composition session-ஐ complete அல்லது cancel செய்யும்போது fire ஆகும்.onCompositionEndCapture: capture phase-இல் fire ஆகும்onCompositionEnd-ன் version.onCompositionUpdate: ஒருCompositionEventhandler function. Input method editor புதிய character பெறும்போது fire ஆகும்.onCompositionUpdateCapture: capture phase-இல் fire ஆகும்onCompositionUpdate-ன் version.onContextMenu: ஒருMouseEventhandler function. User context menu திறக்க முயன்றால் fire ஆகும்.onContextMenuCapture: capture phase-இல் fire ஆகும்onContextMenu-ன் version.onCopy: ஒருClipboardEventhandler function. User clipboard-க்கு ஏதாவது copy செய்ய முயன்றால் fire ஆகும்.onCopyCapture: capture phase-இல் fire ஆகும்onCopy-ன் version.onCut: ஒருClipboardEventhandler function. User clipboard-க்கு ஏதாவது cut செய்ய முயன்றால் fire ஆகும்.onCutCapture: capture phase-இல் fire ஆகும்onCut-ன் version.onDoubleClick: ஒருMouseEventhandler function. User இருமுறை click செய்யும்போது fire ஆகும். Browserdblclickevent-க்கு இணையானது.onDoubleClickCapture: capture phase-இல் fire ஆகும்onDoubleClick-ன் version.onDrag: ஒருDragEventhandler function. User ஏதாவது drag செய்யும் போது fire ஆகும்.onDragCapture: capture phase-இல் fire ஆகும்onDrag-ன் version.onDragEnd: ஒருDragEventhandler function. User drag செய்வதை நிறுத்தும்போது fire ஆகும்.onDragEndCapture: capture phase-இல் fire ஆகும்onDragEnd-ன் version.onDragEnter: ஒருDragEventhandler function. Drag செய்யப்படும் content valid drop target-க்குள் நுழையும் போது fire ஆகும்.onDragEnterCapture: capture phase-இல் fire ஆகும்onDragEnter-ன் version.onDragOver: ஒருDragEventhandler function. Drag செய்யப்படும் content valid drop target மேல் இருக்கும் போது fire ஆகும். Drop செய்ய அனுமதிக்க இங்கேe.preventDefault()call செய்ய வேண்டும்.onDragOverCapture: capture phase-இல் fire ஆகும்onDragOver-ன் version.onDragStart: ஒருDragEventhandler function. User ஒரு element-ஐ drag செய்யத் தொடங்கும்போது fire ஆகும்.onDragStartCapture: capture phase-இல் fire ஆகும்onDragStart-ன் version.onDrop: ஒருDragEventhandler function. ஏதாவது valid drop target மீது drop செய்யப்பட்டால் fire ஆகும்.onDropCapture: capture phase-இல் fire ஆகும்onDrop-ன் version.onFocus: ஒருFocusEventhandler function. Element focus பெறும்போது fire ஆகும். Built-in browserfocusevent போல அல்லாமல், React-இல்onFocusevent bubbles ஆகும்.onFocusCapture: capture phase-இல் fire ஆகும்onFocus-ன் version.onGotPointerCapture: ஒருPointerEventhandler function. Element code மூலம் pointer-ஐ capture செய்யும்போது fire ஆகும்.onGotPointerCaptureCapture: capture phase-இல் fire ஆகும்onGotPointerCapture-ன் version.onKeyDown: ஒருKeyboardEventhandler function. Key press செய்யப்படும் போது fire ஆகும்.onKeyDownCapture: capture phase-இல் fire ஆகும்onKeyDown-ன் version.onKeyPress: ஒருKeyboardEventhandler function. Deprecated. அதற்குப் பதிலாகonKeyDownஅல்லதுonBeforeInputபயன்படுத்துங்கள்.onKeyPressCapture: capture phase-இல் fire ஆகும்onKeyPress-ன் version.onKeyUp: ஒருKeyboardEventhandler function. Key release செய்யப்படும் போது fire ஆகும்.onKeyUpCapture: capture phase-இல் fire ஆகும்onKeyUp-ன் version.onLostPointerCapture: ஒருPointerEventhandler function. Element pointer capture செய்வதை நிறுத்தும்போது fire ஆகும்.onLostPointerCaptureCapture: capture phase-இல் fire ஆகும்onLostPointerCapture-ன் version.onMouseDown: ஒருMouseEventhandler function. Pointer அழுத்தப்படும் போது fire ஆகும்.onMouseDownCapture: capture phase-இல் fire ஆகும்onMouseDown-ன் version.onMouseEnter: ஒருMouseEventhandler function. Pointer ஒரு element-க்குள் நகரும்போது fire ஆகும். இதற்கு capture phase இல்லை. அதற்கு பதிலாக,onMouseLeaveமற்றும்onMouseEnterவிட்டு வெளியேறும் element-இலிருந்து நுழையும் element-க்கு propagate ஆகும்.onMouseLeave: ஒருMouseEventhandler function. Pointer ஒரு element-க்கு வெளியே நகரும்போது fire ஆகும். இதற்கு capture phase இல்லை. அதற்கு பதிலாக,onMouseLeaveமற்றும்onMouseEnterவிட்டு வெளியேறும் element-இலிருந்து நுழையும் element-க்கு propagate ஆகும்.onMouseMove: ஒருMouseEventhandler function. Pointer coordinates மாறும்போது fire ஆகும்.onMouseMoveCapture: capture phase-இல் fire ஆகும்onMouseMove-ன் version.onMouseOut: ஒருMouseEventhandler function. Pointer ஒரு element-க்கு வெளியே நகரும்போது, அல்லது child element-க்குள் நகரும்போது fire ஆகும்.onMouseOutCapture: capture phase-இல் fire ஆகும்onMouseOut-ன் version.onMouseUp: ஒருMouseEventhandler function. Pointer release செய்யப்படும் போது fire ஆகும்.onMouseUpCapture: capture phase-இல் fire ஆகும்onMouseUp-ன் version.onPointerCancel: ஒருPointerEventhandler function. Browser ஒரு pointer interaction-ஐ cancel செய்தால் fire ஆகும்.onPointerCancelCapture: capture phase-இல் fire ஆகும்onPointerCancel-ன் version.onPointerDown: ஒருPointerEventhandler function. Pointer active ஆகும்போது fire ஆகும்.onPointerDownCapture: capture phase-இல் fire ஆகும்onPointerDown-ன் version.onPointerEnter: ஒருPointerEventhandler function. Pointer ஒரு element-க்குள் நகரும்போது fire ஆகும். இதற்கு capture phase இல்லை. அதற்கு பதிலாக,onPointerLeaveமற்றும்onPointerEnterவிட்டு வெளியேறும் element-இலிருந்து நுழையும் element-க்கு propagate ஆகும்.onPointerLeave: ஒருPointerEventhandler function. Pointer ஒரு element-க்கு வெளியே நகரும்போது fire ஆகும். இதற்கு capture phase இல்லை. அதற்கு பதிலாக,onPointerLeaveமற்றும்onPointerEnterவிட்டு வெளியேறும் element-இலிருந்து நுழையும் element-க்கு propagate ஆகும்.onPointerMove: ஒருPointerEventhandler function. Pointer coordinates மாறும்போது fire ஆகும்.onPointerMoveCapture: capture phase-இல் fire ஆகும்onPointerMove-ன் version.onPointerOut: ஒருPointerEventhandler function. Pointer ஒரு element-க்கு வெளியே நகரும்போது, pointer interaction cancel செய்யப்பட்டால், மற்றும் சில பிற காரணங்களால் fire ஆகும்.onPointerOutCapture: capture phase-இல் fire ஆகும்onPointerOut-ன் version.onPointerUp: ஒருPointerEventhandler function. Pointer இனி active இல்லாதபோது fire ஆகும்.onPointerUpCapture: capture phase-இல் fire ஆகும்onPointerUp-ன் version.onPaste: ஒருClipboardEventhandler function. User clipboard-இலிருந்து ஏதாவது paste செய்ய முயன்றால் fire ஆகும்.onPasteCapture: capture phase-இல் fire ஆகும்onPaste-ன் version.onScroll: ஒருEventhandler function. Element scroll செய்யப்பட்டபோது fire ஆகும். இந்த event bubble ஆகாது.onScrollCapture: capture phase-இல் fire ஆகும்onScroll-ன் version.onSelect: ஒருEventhandler function. Input போன்ற editable element-க்குள் selection மாறிய பிறகு fire ஆகும்.contentEditable={true}elements-க்கும் வேலை செய்ய ReactonSelectevent-ஐ விரிவாக்குகிறது. கூடுதலாக, empty selection-க்கும் edits-க்கும் (அவை selection-ஐ பாதிக்கலாம்) fire ஆகும்படி React இதை விரிவாக்குகிறது.onSelectCapture: capture phase-இல் fire ஆகும்onSelect-ன் version.onTouchCancel: ஒருTouchEventhandler function. Browser ஒரு touch interaction-ஐ cancel செய்தால் fire ஆகும்.onTouchCancelCapture: capture phase-இல் fire ஆகும்onTouchCancel-ன் version.onTouchEnd: ஒருTouchEventhandler function. ஒன்று அல்லது அதற்கு மேற்பட்ட touch points அகற்றப்பட்டால் fire ஆகும்.onTouchEndCapture: capture phase-இல் fire ஆகும்onTouchEnd-ன் version.onTouchMove: ஒருTouchEventhandler function. ஒன்று அல்லது அதற்கு மேற்பட்ட touch points நகர்த்தப்பட்டால் fire ஆகும்.onTouchMoveCapture: capture phase-இல் fire ஆகும்onTouchMove-ன் version.onTouchStart: ஒருTouchEventhandler function. ஒன்று அல்லது அதற்கு மேற்பட்ட touch points வைக்கப்படும்போது fire ஆகும்.onTouchStartCapture: capture phase-இல் fire ஆகும்onTouchStart-ன் version.onTransitionEnd: ஒருTransitionEventhandler function. CSS transition முடிந்தபோது fire ஆகும்.onTransitionEndCapture: capture phase-இல் fire ஆகும்onTransitionEnd-ன் version.onWheel: ஒருWheelEventhandler function. User wheel button-ஐ rotate செய்யும்போது fire ஆகும்.onWheelCapture: capture phase-இல் fire ஆகும்onWheel-ன் version.role: ஒரு string. Assistive technologies-க்காக element role-ஐ வெளிப்படையாக குறிப்பிடுகிறது.slot: ஒரு string. Shadow DOM பயன்படுத்தும்போது slot name-ஐ குறிப்பிடுகிறது. React-இல் இதற்கு இணையான pattern பொதுவாக JSX-ஐ props ஆக pass செய்வதன் மூலம் பெறப்படுகிறது, உதாரணமாக<Layout left={<Sidebar />} right={<Content />} />.spellCheck: ஒரு boolean அல்லது null. Explicit ஆகtrueஅல்லதுfalseset செய்தால், spellchecking enable அல்லது disable ஆகும்.tabIndex: ஒரு number. Default Tab button behavior-ஐ override செய்கிறது.-1மற்றும்0அல்லாத values பயன்படுத்துவதை தவிர்க்கவும்.title: ஒரு string. Element-க்கான tooltip text-ஐ குறிப்பிடுகிறது.translate:'yes'அல்லது'no'.'no'pass செய்தால் element content translate செய்யப்படுவதிலிருந்து விலக்கப்படும்.
Custom attributes-ஐயும் props ஆக pass செய்யலாம், உதாரணமாக mycustomprop="someValue". Third-party libraries-உடன் integrate செய்யும்போது இது பயனுள்ளதாக இருக்கலாம். Custom attribute பெயர் lowercase ஆக இருக்க வேண்டும்; on என்று தொடங்கக்கூடாது. Value string ஆக மாற்றப்படும். null அல்லது undefined pass செய்தால், custom attribute நீக்கப்படும்.
இந்த events <form> elements-க்கு மட்டும் fire ஆகும்:
onReset: ஒருEventhandler function. Form reset செய்யப்படும் போது fire ஆகும்.onResetCapture: capture phase-இல் fire ஆகும்onReset-ன் version.onSubmit: ஒருEventhandler function. Form submit செய்யப்படும் போது fire ஆகும்.onSubmitCapture: capture phase-இல் fire ஆகும்onSubmit-ன் version.
இந்த events <dialog> elements-க்கு மட்டும் fire ஆகும். Browser events போல அல்லாமல், React-இல் இவை bubble ஆகும்:
onCancel: ஒருEventhandler function. User dialog-ஐ dismiss செய்ய முயன்றால் fire ஆகும்.onCancelCapture: capture phase-இல் fire ஆகும்onCancel-ன் version.onClose: ஒருEventhandler function. Dialog close செய்யப்பட்டபோது fire ஆகும்.onCloseCapture: capture phase-இல் fire ஆகும்onClose-ன் version.
இந்த events <details> elements-க்கு மட்டும் fire ஆகும். Browser events போல அல்லாமல், React-இல் இவை bubble ஆகும்:
onToggle: ஒருEventhandler function. User details-ஐ toggle செய்யும்போது fire ஆகும்.onToggleCapture: capture phase-இல் fire ஆகும்onToggle-ன் version.
இந்த events <img>, <iframe>, <object>, <embed>, <link>, மற்றும் SVG <image> elements-க்கு fire ஆகும். Browser events போல அல்லாமல், React-இல் இவை bubble ஆகும்:
onLoad: ஒருEventhandler function. Resource load ஆனபோது fire ஆகும்.onLoadCapture: capture phase-இல் fire ஆகும்onLoad-ன் version.onError: ஒருEventhandler function. Resource load ஆக முடியாதபோது fire ஆகும்.onErrorCapture: capture phase-இல் fire ஆகும்onError-ன் version.
இந்த events <audio> மற்றும் <video> போன்ற resources-க்கு fire ஆகும். Browser events போல அல்லாமல், React-இல் இவை bubble ஆகும்:
onAbort: ஒருEventhandler function. Resource முழுமையாக load ஆகாதபோது, ஆனால் error காரணமாக அல்லாதபோது fire ஆகும்.onAbortCapture: capture phase-இல் fire ஆகும்onAbort-ன் version.onCanPlay: ஒருEventhandler function. Play தொடங்க போதுமான data இருக்கும்போது, ஆனால் buffering இல்லாமல் முடிவு வரை play செய்ய போதுமானதாக இல்லாதபோது fire ஆகும்.onCanPlayCapture: capture phase-இல் fire ஆகும்onCanPlay-ன் version.onCanPlayThrough: ஒருEventhandler function. முடிவு வரை buffering இல்லாமல் play செய்ய போதுமான data இருக்கக்கூடும் என்ற நிலையில் fire ஆகும்.onCanPlayThroughCapture: capture phase-இல் fire ஆகும்onCanPlayThrough-ன் version.onDurationChange: ஒருEventhandler function. Media duration update ஆனபோது fire ஆகும்.onDurationChangeCapture: capture phase-இல் fire ஆகும்onDurationChange-ன் version.onEmptied: ஒருEventhandler function. Media empty ஆனபோது fire ஆகும்.onEmptiedCapture: capture phase-இல் fire ஆகும்onEmptied-ன் version.onEncrypted: ஒருEventhandler function. Browser encrypted media-வை சந்திக்கும் போது fire ஆகும்.onEncryptedCapture: capture phase-இல் fire ஆகும்onEncrypted-ன் version.onEnded: ஒருEventhandler function. Play செய்ய எதுவும் மீதமில்லாததால் playback நிற்கும்போது fire ஆகும்.onEndedCapture: capture phase-இல் fire ஆகும்onEnded-ன் version.onError: ஒருEventhandler function. Resource load ஆக முடியாதபோது fire ஆகும்.onErrorCapture: capture phase-இல் fire ஆகும்onError-ன் version.onLoadedData: ஒருEventhandler function. தற்போதைய playback frame load ஆனபோது fire ஆகும்.onLoadedDataCapture: capture phase-இல் fire ஆகும்onLoadedData-ன் version.onLoadedMetadata: ஒருEventhandler function. Metadata load ஆனபோது fire ஆகும்.onLoadedMetadataCapture: capture phase-இல் fire ஆகும்onLoadedMetadata-ன் version.onLoadStart: ஒருEventhandler function. Browser resource-ஐ load செய்யத் தொடங்கும்போது fire ஆகும்.onLoadStartCapture: capture phase-இல் fire ஆகும்onLoadStart-ன் version.onPause: ஒருEventhandler function. Media pause செய்யப்பட்டபோது fire ஆகும்.onPauseCapture: capture phase-இல் fire ஆகும்onPause-ன் version.onPlay: ஒருEventhandler function. Media இனி paused இல்லாதபோது fire ஆகும்.onPlayCapture: capture phase-இல் fire ஆகும்onPlay-ன் version.onPlaying: ஒருEventhandler function. Media play செய்யத் தொடங்கும்போது அல்லது மீண்டும் தொடங்கும்போது fire ஆகும்.onPlayingCapture: capture phase-இல் fire ஆகும்onPlaying-ன் version.onProgress: ஒருEventhandler function. Resource load ஆகிக்கொண்டிருக்கும் போது அவ்வப்போது fire ஆகும்.onProgressCapture: capture phase-இல் fire ஆகும்onProgress-ன் version.onRateChange: ஒருEventhandler function. Playback rate மாறும்போது fire ஆகும்.onRateChangeCapture: capture phase-இல் fire ஆகும்onRateChange-ன் version.onResize: ஒருEventhandler function. Video size மாறும்போது fire ஆகும்.onResizeCapture: capture phase-இல் fire ஆகும்onResize-ன் version.onSeeked: ஒருEventhandler function. Seek operation முடிந்தபோது fire ஆகும்.onSeekedCapture: capture phase-இல் fire ஆகும்onSeeked-ன் version.onSeeking: ஒருEventhandler function. Seek operation தொடங்கும்போது fire ஆகும்.onSeekingCapture: capture phase-இல் fire ஆகும்onSeeking-ன் version.onStalled: ஒருEventhandler function. Browser data-க்காக காத்திருக்கும்போது ஆனால் அது தொடர்ந்து load ஆகாதபோது fire ஆகும்.onStalledCapture: capture phase-இல் fire ஆகும்onStalled-ன் version.onSuspend: ஒருEventhandler function. Resource loading suspend செய்யப்பட்டபோது fire ஆகும்.onSuspendCapture: capture phase-இல் fire ஆகும்onSuspend-ன் version.onTimeUpdate: ஒருEventhandler function. தற்போதைய playback time update ஆனபோது fire ஆகும்.onTimeUpdateCapture: capture phase-இல் fire ஆகும்onTimeUpdate-ன் version.onVolumeChange: ஒருEventhandler function. Volume மாறியபோது fire ஆகும்.onVolumeChangeCapture: capture phase-இல் fire ஆகும்onVolumeChange-ன் version.onWaiting: ஒருEventhandler function. Temporary data இல்லாமையால் playback நிற்கும்போது fire ஆகும்.onWaitingCapture: capture phase-இல் fire ஆகும்onWaiting-ன் version.
Caveats
childrenமற்றும்dangerouslySetInnerHTMLஇரண்டையும் ஒரே நேரத்தில் pass செய்ய முடியாது.- சில events (
onAbortமற்றும்onLoadபோன்றவை) browser-இல் bubble ஆகாது, ஆனால் React-இல் bubble ஆகும்.
ref callback function
Ref object-க்கு பதிலாக (useRef return செய்யும் object போன்றது), ref attribute-க்கு function pass செய்யலாம்.
<div ref={(node) => {
console.log('இணைக்கப்பட்டது', node);
return () => {
console.log('சுத்தம் செய்யவும்', node)
}
}}>ref callback பயன்படுத்தும் உதாரணத்தை பார்க்கவும்.
<div> DOM node screen-க்கு சேர்க்கப்படும் போது, DOM node-ஐ argument ஆக வைத்து React உங்கள் ref callback-ஐ call செய்யும். அந்த <div> DOM node நீக்கப்படும் போது, callback return செய்த cleanup function-ஐ React call செய்யும்.
நீங்கள் வேறு ref callback pass செய்யும் ஒவ்வொரு முறையும் React உங்கள் ref callback-ஐ call செய்யும். மேலுள்ள உதாரணத்தில், (node) => { ... } ஒவ்வொரு render-இலும் வேறு function ஆகும். உங்கள் component re-render ஆகும்போது, முந்தைய function null argument-உடன் call செய்யப்படும்; அடுத்த function DOM node-உடன் call செய்யப்படும்.
Parameters
node: ஒரு DOM node. Ref attach ஆகும்போது React DOM node-ஐ உங்களுக்கு pass செய்யும். ஒவ்வொரு render-இலும்refcallback-க்காக அதே function reference-ஐ pass செய்யாவிட்டால், component re-render ஆகும் ஒவ்வொரு முறையும் callback தற்காலிகமாக cleanup செய்யப்பட்டு மீண்டும் உருவாக்கப்படும்.
Returns
- optional
cleanup function:refdetach ஆகும்போது React cleanup function-ஐ call செய்யும்.refcallback ஒரு function return செய்யாவிட்டால்,refdetach ஆகும் போது React callback-ஐ மீண்டும்nullargument-உடன் call செய்யும். இந்த behavior எதிர்கால version-இல் நீக்கப்படும்.
Caveats
- Strict Mode on ஆக இருந்தால், முதல் real setup-க்கு முன் React development-க்கு மட்டும் கூடுதல் setup+cleanup cycle ஒன்றை run செய்யும். உங்கள் cleanup logic setup logic-ஐ “mirror” செய்கிறதா, setup செய்கிறதை நிறுத்துகிறதா அல்லது undo செய்கிறதா என்பதை உறுதி செய்யும் stress-test இது. இது பிரச்சினை தருமானால், cleanup function-ஐ implement செய்யுங்கள்.
- நீங்கள் வேறு
refcallback pass செய்தால், React முந்தைய callback-ன் cleanup function-ஐ call செய்யும். Cleanup function define செய்யப்படவில்லை என்றால்,refcallbacknullargument-உடன் call செய்யப்படும். அடுத்த function DOM node-உடன் call செய்யப்படும்.
React event object
உங்கள் event handlers ஒரு React event object-ஐப் பெறும். இது சில நேரங்களில் “synthetic event” என்றும் அழைக்கப்படுகிறது.
<button onClick={e => {
console.log(e); // React event object
}} />இது underlying DOM events போலவே அதே standard-ஐ பின்பற்றுகிறது, ஆனால் சில browser inconsistencies-ஐ சரிசெய்கிறது.
சில React events browser-ன் native events-க்கு நேரடியாக map ஆகாது. உதாரணமாக onMouseLeave-இல், e.nativeEvent ஒரு mouseout event-ஐ point செய்யும். இந்த specific mapping public API-ன் பகுதி அல்ல; எதிர்காலத்தில் மாறலாம். ஏதாவது காரணத்திற்காக underlying browser event தேவைப்பட்டால், அதை e.nativeEvent-இலிருந்து வாசிக்கவும்.
Properties
React event objects சில standard Event properties-ஐ implement செய்கின்றன:
bubbles: ஒரு boolean. Event DOM வழியாக bubble ஆகுமா என்பதை return செய்கிறது.cancelable: ஒரு boolean. Event cancel செய்ய முடியுமா என்பதை return செய்கிறது.currentTarget: ஒரு DOM node. React tree-இல் current handler attach செய்யப்பட்ட node-ஐ return செய்கிறது.defaultPrevented: ஒரு boolean.preventDefaultcall செய்யப்பட்டதா என்பதை return செய்கிறது.eventPhase: ஒரு number. Event தற்போது எந்த phase-இல் உள்ளது என்பதை return செய்கிறது.isTrusted: ஒரு boolean. Event user மூலம் தொடங்கப்பட்டதா என்பதை return செய்கிறது.target: ஒரு DOM node. Event நிகழ்ந்த node-ஐ return செய்கிறது (அது தூரத்தில் உள்ள child ஆக இருக்கலாம்).timeStamp: ஒரு number. Event நிகழ்ந்த நேரத்தை return செய்கிறது.
கூடுதலாக, React event objects இந்த properties-ஐ வழங்குகின்றன:
nativeEvent: ஒரு DOMEvent. Original browser event object.
Methods
React event objects சில standard Event methods-ஐ implement செய்கின்றன:
preventDefault(): Event-க்கான default browser action-ஐத் தடுக்கிறது.stopPropagation(): React tree வழியாக event propagation-ஐ நிறுத்துகிறது.
கூடுதலாக, React event objects இந்த methods-ஐ வழங்குகின்றன:
isDefaultPrevented():preventDefaultcall செய்யப்பட்டதா என்பதை காட்டும் boolean value-ஐ return செய்கிறது.isPropagationStopped():stopPropagationcall செய்யப்பட்டதா என்பதை காட்டும் boolean value-ஐ return செய்கிறது.persist(): React DOM உடன் பயன்படுத்தப்படாது. React Native-இல், event பிறகு event-ன் properties-ஐ வாசிக்க இதை call செய்யுங்கள்.isPersistent(): React DOM உடன் பயன்படுத்தப்படாது. React Native-இல்,persistcall செய்யப்பட்டதா என்பதை return செய்கிறது.
Caveats
currentTarget,eventPhase,target, மற்றும்typevalues உங்கள் React code எதிர்பார்க்கும் values-ஐ reflect செய்கின்றன. Internally, React event handlers-ஐ root-இல் attach செய்கிறது, ஆனால் இது React event objects-இல் reflect ஆகாது. உதாரணமாக,e.currentTargetunderlyinge.nativeEvent.currentTarget-ஐப் போல இருக்க வேண்டியதில்லை. Polyfilled events-க்கு,e.type(React event type)e.nativeEvent.type(underlying type)-இலிருந்து மாறுபடலாம்.
AnimationEvent handler function
CSS animation events-க்கான event handler type.
<div
onAnimationStart={e => console.log('onAnimationStart')}
onAnimationIteration={e => console.log('onAnimationIteration')}
onAnimationEnd={e => console.log('onAnimationEnd')}
/>Parameters
e: இந்த கூடுதல்AnimationEventproperties கொண்ட React event object:
ClipboardEvent handler function
Clipboard API events-க்கான event handler type.
<input
onCopy={e => console.log('onCopy')}
onCut={e => console.log('onCut')}
onPaste={e => console.log('onPaste')}
/>Parameters
-
e: இந்த கூடுதல்ClipboardEventproperties கொண்ட React event object:
CompositionEvent handler function
Input method editor (IME) events-க்கான event handler type.
<input
onCompositionStart={e => console.log('onCompositionStart')}
onCompositionUpdate={e => console.log('onCompositionUpdate')}
onCompositionEnd={e => console.log('onCompositionEnd')}
/>Parameters
e: இந்த கூடுதல்CompositionEventproperties கொண்ட React event object:
DragEvent handler function
HTML Drag and Drop API events-க்கான event handler type.
<>
<div
draggable={true}
onDragStart={e => console.log('onDragStart')}
onDragEnd={e => console.log('onDragEnd')}
>
இழுக்கும் மூலம்
</div>
<div
onDragEnter={e => console.log('onDragEnter')}
onDragLeave={e => console.log('onDragLeave')}
onDragOver={e => { e.preventDefault(); console.log('onDragOver'); }}
onDrop={e => console.log('onDrop')}
>
Drop இலக்கு
</div>
</>Parameters
-
e: இந்த கூடுதல்DragEventproperties கொண்ட React event object:இதில் inherited
MouseEventproperties-உம் அடங்கும்:altKeybuttonbuttonsctrlKeyclientXclientYgetModifierState(key)metaKeymovementXmovementYpageXpageYrelatedTargetscreenXscreenYshiftKey
இதில் inherited
UIEventproperties-உம் அடங்கும்:
FocusEvent handler function
Focus events-க்கான event handler type.
<input
onFocus={e => console.log('onFocus')}
onBlur={e => console.log('onBlur')}
/>Parameters
-
e: இந்த கூடுதல்FocusEventproperties கொண்ட React event object:இதில் inherited
UIEventproperties-உம் அடங்கும்:
Event handler function
Generic events-க்கான event handler type.
Parameters
e: கூடுதல் properties இல்லாத React event object.
InputEvent handler function
onBeforeInput event-க்கான event handler type.
<input onBeforeInput={e => console.log('onBeforeInput')} />Parameters
e: இந்த கூடுதல்InputEventproperties கொண்ட React event object:
KeyboardEvent handler function
Keyboard events-க்கான event handler type.
<input
onKeyDown={e => console.log('onKeyDown')}
onKeyUp={e => console.log('onKeyUp')}
/>Parameters
-
e: இந்த கூடுதல்KeyboardEventproperties கொண்ட React event object:altKeycharCodecodectrlKeygetModifierState(key)keykeyCodelocalemetaKeylocationrepeatshiftKeywhich
இதில் inherited
UIEventproperties-உம் அடங்கும்:
MouseEvent handler function
Mouse events-க்கான event handler type.
<div
onClick={e => console.log('onClick')}
onMouseEnter={e => console.log('onMouseEnter')}
onMouseOver={e => console.log('onMouseOver')}
onMouseDown={e => console.log('onMouseDown')}
onMouseUp={e => console.log('onMouseUp')}
onMouseLeave={e => console.log('onMouseLeave')}
/>Parameters
-
e: இந்த கூடுதல்MouseEventproperties கொண்ட React event object:altKeybuttonbuttonsctrlKeyclientXclientYgetModifierState(key)metaKeymovementXmovementYpageXpageYrelatedTargetscreenXscreenYshiftKey
இதில் inherited
UIEventproperties-உம் அடங்கும்:
PointerEvent handler function
Pointer events-க்கான event handler type.
<div
onPointerEnter={e => console.log('onPointerEnter')}
onPointerMove={e => console.log('onPointerMove')}
onPointerDown={e => console.log('onPointerDown')}
onPointerUp={e => console.log('onPointerUp')}
onPointerLeave={e => console.log('onPointerLeave')}
/>Parameters
-
e: இந்த கூடுதல்PointerEventproperties கொண்ட React event object:இதில் inherited
MouseEventproperties-உம் அடங்கும்:altKeybuttonbuttonsctrlKeyclientXclientYgetModifierState(key)metaKeymovementXmovementYpageXpageYrelatedTargetscreenXscreenYshiftKey
இதில் inherited
UIEventproperties-உம் அடங்கும்:
TouchEvent handler function
Touch events-க்கான event handler type.
<div
onTouchStart={e => console.log('onTouchStart')}
onTouchMove={e => console.log('onTouchMove')}
onTouchEnd={e => console.log('onTouchEnd')}
onTouchCancel={e => console.log('onTouchCancel')}
/>Parameters
-
e: இந்த கூடுதல்TouchEventproperties கொண்ட React event object:இதில் inherited
UIEventproperties-உம் அடங்கும்:
TransitionEvent handler function
CSS transition events-க்கான event handler type.
<div
onTransitionEnd={e => console.log('onTransitionEnd')}
/>Parameters
e: இந்த கூடுதல்TransitionEventproperties கொண்ட React event object:
UIEvent handler function
Generic UI events-க்கான event handler type.
<div
onScroll={e => console.log('onScroll')}
/>Parameters
e: இந்த கூடுதல்UIEventproperties கொண்ட React event object:
WheelEvent handler function
onWheel event-க்கான event handler type.
<div
onWheel={e => console.log('onWheel')}
/>Parameters
-
e: இந்த கூடுதல்WheelEventproperties கொண்ட React event object:இதில் inherited
MouseEventproperties-உம் அடங்கும்:altKeybuttonbuttonsctrlKeyclientXclientYgetModifierState(key)metaKeymovementXmovementYpageXpageYrelatedTargetscreenXscreenYshiftKey
இதில் inherited
UIEventproperties-உம் அடங்கும்:
Usage
CSS styles பயன்படுத்துதல்
React-இல், CSS class-ஐ className மூலம் குறிப்பிடுகிறீர்கள். இது HTML-இல் உள்ள class attribute போலவே வேலை செய்கிறது:
<img className="avatar" />பிறகு அதற்கான CSS rules-ஐ தனி CSS file-இல் எழுதுகிறீர்கள்:
/* In your CSS */
.avatar {
border-radius: 50%;
}CSS files-ஐ எப்படி சேர்க்க வேண்டும் என்று React கட்டாயப்படுத்தாது. நேரடியான நிலையில், உங்கள் HTML-க்கு <link> tag ஒன்றை சேர்ப்பீர்கள். Build tool அல்லது framework பயன்படுத்தினால், உங்கள் project-க்கு CSS file சேர்ப்பது எப்படி என்பதை அதன் documentation-ல் பார்க்கவும்.
சில நேரங்களில் style values data-வைப் பொறுத்திருக்கும். சில styles-ஐ dynamic ஆக pass செய்ய style attribute பயன்படுத்துங்கள்:
<img
className="avatar"
style={{
width: user.imageSize,
height: user.imageSize
}}
/>மேலுள்ள உதாரணத்தில், style={{}} என்பது special syntax அல்ல; style={ } JSX curly braces-க்குள் உள்ள வழக்கமான {} object மட்டுமே. உங்கள் styles JavaScript variables-ஐ சார்ந்திருக்கும்போது மட்டும் style attribute பயன்படுத்த பரிந்துரைக்கிறோம்.
export default function Avatar({ user }) { return ( <img src={user.imageUrl} alt={user.name + ' அவர்களின் படம்'} className="avatar" style={{ width: user.imageSize, height: user.imageSize }} /> ); }
Deep Dive
CSS classes-ஐ conditionally apply செய்ய, JavaScript பயன்படுத்தி className string-ஐ நீங்களே உருவாக்க வேண்டும்.
உதாரணமாக, className={'row ' + (isSelected ? 'selected': '')} என்பது isSelected true ஆக உள்ளதா என்பதன் அடிப்படையில் className="row" அல்லது className="row selected" உருவாக்கும்.
இதை அதிகம் readable ஆக்க, classnames போன்ற சிறிய helper library-ஐ பயன்படுத்தலாம்:
import cn from 'classnames';
function Row({ isSelected }) {
return (
<div className={cn('row', isSelected && 'selected')}>
...
</div>
);
}பல conditional classes இருந்தால் இது குறிப்பாக வசதியானது:
import cn from 'classnames';
function Row({ isSelected, size }) {
return (
<div className={cn('row', {
selected: isSelected,
large: size === 'large',
small: size === 'small',
})}>
...
</div>
);
}Ref மூலம் DOM node-ஐ கையாளுதல்
சில நேரங்களில், JSX-இல் உள்ள tag-க்கு தொடர்புடைய browser DOM node-ஐ பெற வேண்டியிருக்கும். உதாரணமாக, button click செய்யும்போது <input> focus ஆக வேண்டும் என்றால், browser <input> DOM node-இல் focus() call செய்ய வேண்டும்.
ஒரு tag-க்கான browser DOM node-ஐ பெற, ref ஒன்றை declare செய்து அதை அந்த tag-க்கு ref attribute ஆக pass செய்யுங்கள்:
import { useRef } from 'react';
export default function Form() {
const inputRef = useRef(null);
// ...
return (
<input ref={inputRef} />
// ...Screen-க்கு render ஆன பிறகு React DOM node-ஐ inputRef.current-க்குள் வைக்கும்.
import { useRef } from 'react'; export default function Form() { const inputRef = useRef(null); function handleClick() { inputRef.current.focus(); } return ( <> <input ref={inputRef} /> <button onClick={handleClick}> Input-ஐ focus செய் </button> </> ); }
Refs மூலம் DOM-ஐ கையாளுவது பற்றி மேலும் வாசிக்கவும், மேலும் இன்னும் பல examples-ஐ பார்க்கவும்.
மேம்பட்ட use cases-க்கு, ref attribute callback function-ஐயும் ஏற்கும்.
Inner HTML-ஐ ஆபத்தான முறையில் set செய்தல்
Raw HTML string-ஐ ஒரு element-க்கு இவ்வாறு pass செய்யலாம்:
const markup = { __html: '<p>சில raw html</p>' };
return <div dangerouslySetInnerHTML={markup} />;இது ஆபத்தானது. Underlying DOM innerHTML property போலவே, நீங்கள் மிகுந்த கவனத்துடன் நடக்க வேண்டும்! Markup முற்றிலும் நம்பத்தகுந்த source-இலிருந்து வராத வரை, இவ்வாறு XSS vulnerability உருவாக்குவது சாத்தியம்.
உதாரணமாக, Markdown-ஐ HTML ஆக மாற்றும் Markdown library பயன்படுத்தினால், அதன் parser-இல் bugs இல்லை என்று நீங்கள் நம்பினால், மற்றும் user தன்னுடைய input-ஐ மட்டுமே பார்க்கிறான் என்றால், கிடைக்கும் HTML-ஐ இவ்வாறு காட்டலாம்:
import { Remarkable } from 'remarkable'; const md = new Remarkable(); function renderMarkdownToHTML(markdown) { // This is ONLY safe because the output HTML // is shown to the same user, and because you // trust this Markdown parser to not have bugs. const renderedHTML = md.render(markdown); return {__html: renderedHTML}; } export default function MarkdownPreview({ markdown }) { const markup = renderMarkdownToHTML(markdown); return <div dangerouslySetInnerHTML={markup} />; }
renderMarkdownToHTML function-இல் மேலுள்ள example செய்வது போல, {__html} object HTML உருவாகும் இடத்திற்கு மிக அருகில் create செய்யப்பட வேண்டும். இதனால் உங்கள் code-இல் பயன்படுத்தப்படும் raw HTML அனைத்தும் தெளிவாக அப்படியே mark செய்யப்படும்; மேலும் HTML கொண்டிருக்கும் என்று நீங்கள் எதிர்பார்க்கும் variables மட்டுமே dangerouslySetInnerHTML-க்கு pass செய்யப்படும். <div dangerouslySetInnerHTML={{__html: markup}} /> போல object-ஐ inline ஆக create செய்வது பரிந்துரைக்கப்படாது.
Arbitrary HTML render செய்வது ஏன் ஆபத்தானது என்பதை பார்க்க, மேலுள்ள code-ஐ இதனால் மாற்றுங்கள்:
const post = {
// Imagine this content is stored in the database.
content: `<img src="" onerror='alert("நீங்கள் தாக்கப்பட்டுள்ளீர்கள்")'>`
};
export default function MarkdownPreview() {
// 🔴 SECURITY HOLE: passing untrusted input to dangerouslySetInnerHTML
const markup = { __html: post.content };
return <div dangerouslySetInnerHTML={markup} />;
}HTML-இல் embed செய்யப்பட்ட code run ஆகும். ஒரு attacker இந்த security hole-ஐ பயன்படுத்தி user தகவலை திருடலாம் அல்லது அவர்களுக்குப் பதிலாக actions செய்யலாம். நம்பத்தகுந்த மற்றும் sanitized data உடன் மட்டுமே dangerouslySetInnerHTML பயன்படுத்துங்கள்.
Mouse events கையாளுதல்
இந்த example சில பொதுவான mouse events மற்றும் அவை எப்போது fire ஆகின்றன என்பதை காட்டுகிறது.
export default function MouseExample() { return ( <div onMouseEnter={e => console.log('onMouseEnter (parent)')} onMouseLeave={e => console.log('onMouseLeave (parent)')} > <button onClick={e => console.log('onClick (first button)')} onMouseDown={e => console.log('onMouseDown (first button)')} onMouseEnter={e => console.log('onMouseEnter (first button)')} onMouseLeave={e => console.log('onMouseLeave (first button)')} onMouseOver={e => console.log('onMouseOver (first button)')} onMouseUp={e => console.log('onMouseUp (first button)')} > முதல் button </button> <button onClick={e => console.log('onClick (second button)')} onMouseDown={e => console.log('onMouseDown (second button)')} onMouseEnter={e => console.log('onMouseEnter (second button)')} onMouseLeave={e => console.log('onMouseLeave (second button)')} onMouseOver={e => console.log('onMouseOver (second button)')} onMouseUp={e => console.log('onMouseUp (second button)')} > இரண்டாவது button </button> </div> ); }
Pointer events கையாளுதல்
இந்த example சில பொதுவான pointer events மற்றும் அவை எப்போது fire ஆகின்றன என்பதை காட்டுகிறது.
export default function PointerExample() { return ( <div onPointerEnter={e => console.log('onPointerEnter (parent)')} onPointerLeave={e => console.log('onPointerLeave (parent)')} style={{ padding: 20, backgroundColor: '#ddd' }} > <div onPointerDown={e => console.log('onPointerDown (first child)')} onPointerEnter={e => console.log('onPointerEnter (first child)')} onPointerLeave={e => console.log('onPointerLeave (first child)')} onPointerMove={e => console.log('onPointerMove (first child)')} onPointerUp={e => console.log('onPointerUp (first child)')} style={{ padding: 20, backgroundColor: 'lightyellow' }} > முதல் child </div> <div onPointerDown={e => console.log('onPointerDown (second child)')} onPointerEnter={e => console.log('onPointerEnter (second child)')} onPointerLeave={e => console.log('onPointerLeave (second child)')} onPointerMove={e => console.log('onPointerMove (second child)')} onPointerUp={e => console.log('onPointerUp (second child)')} style={{ padding: 20, backgroundColor: 'lightblue' }} > இரண்டாவது child </div> </div> ); }
Focus events கையாளுதல்
React-இல், focus events bubble ஆகும். Focusing அல்லது blurring events parent element-க்கு வெளியிலிருந்து தொடங்கியதா என்பதை வேறுபடுத்த currentTarget மற்றும் relatedTarget பயன்படுத்தலாம். Child focus ஆகுதல், parent element focus ஆகுதல், மற்றும் முழு subtree-க்குள் focus நுழைவதையோ வெளியேறுவதையோ detect செய்வது எப்படி என்பதை இந்த example காட்டுகிறது.
export default function FocusExample() { return ( <div tabIndex={1} onFocus={(e) => { if (e.currentTarget === e.target) { console.log('focused parent'); } else { console.log('focused child', e.target.name); } if (!e.currentTarget.contains(e.relatedTarget)) { // Not triggered when swapping focus between children console.log('focus entered parent'); } }} onBlur={(e) => { if (e.currentTarget === e.target) { console.log('unfocused parent'); } else { console.log('unfocused child', e.target.name); } if (!e.currentTarget.contains(e.relatedTarget)) { // Not triggered when swapping focus between children console.log('focus left parent'); } }} > <label> முதல் பெயர்: <input name="firstName" /> </label> <label> கடைசி பெயர்: <input name="lastName" /> </label> </div> ); }
Keyboard events கையாளுதல்
இந்த example சில பொதுவான keyboard events மற்றும் அவை எப்போது fire ஆகின்றன என்பதை காட்டுகிறது.
export default function KeyboardExample() { return ( <label> முதல் பெயர்: <input name="firstName" onKeyDown={e => console.log('onKeyDown:', e.key, e.code)} onKeyUp={e => console.log('onKeyUp:', e.key, e.code)} /> </label> ); }