I’m working through Vlad’s Office Hours 4 presentation and finding it very useful (for a newbie getting into HTML/React/JS/JSX). I have an issue and a question, relating to my current custom component code:
Index.js
events
The Issue:
Retrurn_input
I’ve assumed the attributes/events are standard HTML names. However, the onChange and OnKeyDown events (in the screen-shot above) are onchange and onkeydown in HTML (HTML Event Attributes); these lower-case names don’t work in the Custom Component.
What am I missing?
The question:
onKey
This onKey code is my attempt at ‘morphing’ a W3Cschools example (KeyboardEvent key Property) into this custom component (following Vlad’s onChange example event). It runs, but returns ‘undefined’ (null?) for the key value. (When working this will be used to detect ‘Enter’ to terminate the input … note that this new (to me) ‘key’ property replaces the depreciated ‘keycode’; an Enter key press returns ‘Enter’ rather than 13).
Thanks Vlad, that helped a lot! I see more about the .target property; I was (incorrectly) associating the onkey handler with the input element.
The code now ‘returns’ (via context block) the input value from the onKeyPress handler … need to work on the logic so it’s only on an Enter press.
Any comments about Issue 1 above: the all-lower-case names in HTML for the event handlers, versus the semi-camel-case names needed in the custom component element?
Any comments about Issue 1 above: the all-lower-case names in HTML for the event handlers, versus the semi-camel-case names needed in the custom component element?
yes, this is how it works in React, take a look at the link below