I am trying to learn composition API and move away from options api as vue3 seems to be moving towards it. I am doing a simple example where a user enters in an input box the ticker and then the number of shares in the input box next to it. When you click off it adds it to the array
Tag: javascript
I need to detect focus event on all HTML input elements on page without addEventListener and without HTML attribute
I need to detect focus event on all HTML input elements on the page without using addEventListener and without HTML attributes I was able to do that with the click event by: But when i do like that for onfocus it just fires when the focus occurs in the document itself. Is there a way I could to it the
This code keeps returning ‘undefined’ for (names[i]). what am I doing wrong?
This code keeps returning ‘undefined’ for (names[i]). When I console.log() it loops through the array and prints Hello (names[i]) or Good Bye (names[i])what am I doing wrong? Answer Your issue is that you’re passing the name in as an argument to the speak function, however, in your definitio…
React Hook useCallback received a function whose dependencies are unknown. Pass an inline function instead. useMemo doesn’t work
How can i fix this? I see question like this where people said that useMemo can help. But this is not about like that situation and useMemo fix doesn’t work and create just more bugs. Answer can you try this instead? useCallback takes two params.. an inline function, and a dependency array.
Having an issue with Javascript spread
Consider the two objects: obj1 obj2 I’m trying to do the following: The intended output is: However, what I’m getting is: It’s essentially overwriting obj1, not merging them. How do I merge and overwrite? Thanks! Answer You’ll have to use spread operator like below.
Reverse Isometric Projection in Javascript
I have a function which converts some 3D coords (x, y, z) into a position in the screen (width, height), with an isometric perspective (true isometric, not dimetric). So, for better clarification, here we have the blue lines, which represents the 2D Screen, and the black lines, which represents the 3D isometr…
HTML5 Gamepad API TypeError
I’m trying to write some code to get a gamepad and list the axes’ position: and get an Uncaught TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator)) . Would really appreciate help. Answer getGamepads returns sequence<Gamepad?>. You’re using destructurin…
How to capture when dropdown is open on React
Is there a way to tell when the dropdown is open and also closed? onfocus and onblur doesn’t seem to be working. Answer You should use useState to keep track of the dropdown status. It would look something like this: I have tied it into the handleSelect function, which will probably do more than just ke…
Getting array of school values from all objects using JS
Hello I am new to the JavaScript language. I have a table1.data property that’s an array of objects with data about a school like: Can I perhaps get an array of the telephone values from all the objects using JS? Please help. Answer All you need to do it traverse the items in the data, while grabbing th…
Vue3 use ref from third party package in setup script
I’m using Vue 3 for my project and need to get use a ref from a third-party ReCaptcha package during the submission of a form. The code does not recognize the ref name since I did not personally create this ref: It’s used in the template like this: Usage can be found in the docs for this package h…