Latest Questions

Get Answers to Your Coding Questions

73
Votes
Published 15 Apr, 2022
Javascript - React Router v5: history.push() changes the address bar, but does not change the page

Instead of using BrowserRouter, use Router from react-router-dom You could see the example here import { Router, Route, Switch, useHistory, create } from 'react-router-dom'; import { createBrowserHis...

108
Votes
Published 15 Apr, 2022
Javascript - Functions are not valid as a React child. This may happen if you return a Component instead of from render

You are using it as a regular component, but it's actually a function that returns a component. Try doing something like this: const NewComponent = NewHOC(Movie) And you will use it like this: Here...

146
Votes
Published 15 Apr, 2022
Javascript - Number prime test in JavaScript

Time complexity: O(sqrt(n)) Space complexity: O(1) const isPrime = num => { for(let i = 2, s = Math.sqrt(num); i 1; }

64
Votes
Published 15 Apr, 2022
Javascript - short hand array if statement

You can use a for loop, for example: for (let i = 0; i < deaths.length; i++) { if (deaths[i].GetComponent('HealthComponent')._alive == 0) { // do your stuff... } } or you can use forEach() bui...

77
Votes
Published 15 Apr, 2022
Javascript - Javascript search bar displaying holes in place of not displayed cards

You're hiding the card but keeping the col-md-4 div. You can merge the col-md-4 and card divs.

30
Votes
Published 15 Apr, 2022
Javascript - How to filter the member counter in discord.js v13

You can just filter through all the members in a server and remove all the members which are bots by using .filter(). You can then update your code to: module.exports = async(message, args, cmd, cli...

90
Votes
Published 15 Apr, 2022
Javascript - How can I navigate to another route from actions in Vue's Pinia store?

The only place that you need to import vue-router is in your router file. You can then use it anywhere in the app, by importing YOUR router file (which implrments vue-router). So all you need to do in...

52
Votes
Published 15 Apr, 2022
Javascript - Click handler being invoked twice on same element

This is because of Event bubbling. What's happening is : You tigger the click event on inner. The event listener of inner is called. The click event bubbles up to outer. The event listener of outer i...

95
Votes
Published 15 Apr, 2022
Javascript - stopping and restarting an interval (or timeout?)

You need to assign the interval to a global variable, and use this in the call to clearInterval(). You also should get the hour inside the listMeds function. Otherwise you'll always be checking the ti...

10
Votes
Published 15 Apr, 2022
Javascript - I am getting RangeError: Maximum call stack size exceeded error in Javascript

As you wrote yourself, "Repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle". In your implementation, fn calls itself infinitely. In the process, the ja...

315
Votes
Published 15 Apr, 2022
Javascript - Check if a value is an object in JavaScript

UPDATE: This answer is incomplete and gives misleading results. For example, null is also considered of type object in JavaScript, not to mention several other edge cases. Follow the recommendation be...

1851
Votes
Published 15 Apr, 2022
Javascript - How can I remove a specific item from an array?

Find the index of the array element you want to remove using indexOf, and then remove that index with splice. The splice() method changes the contents of an array by removing existing elements and/or...

14
Votes
Published 15 Apr, 2022
Javascript - Find unique node number given x and y coordinates

This is a fairly straightforward 'zip' with an added map of previously seen points, here tracked in an object keyed by the JSON string of each point, and retrieving/setting the next id using logical n...

74
Votes
Published 15 Apr, 2022
Javascript - Testing objects for ancestor/descendent relationship in JavaScript or Jquery

In jQuery ancestors using jQuery objects I suggested if ($(obj1).parents().index($(obj2)) >= 0) { // obj1 is a descendant of obj2 }

37
Votes
Published 15 Apr, 2022
Javascript - Send messages between apps within same browser window

The parent must dispatch the message from the window of the target (child process, iframe in your case) not from the window object of the parent: const child = document.querySelector('iframe').content...

60
Votes
Published 15 Apr, 2022
Javascript - Advice on Javascript Promises script

It looks like this is the section that's causing problems: for(url of urls) { p = p.then(() => fetchOne(url)); } Here you're creating a global variable url, and since it's running asynch...

102
Votes
Published 15 Apr, 2022
Javascript - Redis Command To Sort Keys

Redis returns keys, using KEYS (don't use it in production!) or SCAN, unordered. There is no "fancy" API to return them sorted but you can do it in the client application.

74
Votes
Published 15 Apr, 2022
Javascript - Using reduce() to find min and max values?

The trick consist in provide an empty Array as initialValue Parameter arr.reduce(callback, [initialValue]) initialValue [Optional] Value to use as the first argument to the first call of the c...

90
Votes
Published 15 Apr, 2022
Javascript - Remove Specific HTML Component After Successful Response With JavaScript Fetch API

You can use the closest() method for finding the image componenet closest to the button returned by e.submitter. const forms = document.querySelectorAll('.upload-form-js'), uploadDetailsComponent...

23
Votes
Published 15 Apr, 2022
Javascript - Configure Next Js For Images For External Domains

You are supposed to export a single configuration object. First, Install 'next-compose-plugins': npm install --save next-compose-plugins Import it: const withPlugins = require('next-compose-plugins')...

67
Votes
Published 15 Apr, 2022
Javascript - auto fill form without id tampermonkey

I personally prefer to use jQuery over pure javascript in tampermonkey because it gives me more control such as loading the script when the DOM is ready. i.e. wrap the function in a $(document).ready(...

12
Votes
Published 15 Apr, 2022
Javascript - JavaScript onclick event handlers not functioning properly

There's not really a "ready" event like that. If you want to do things at what's commonly thought of as the "ready" point, you'll need to use a framework. Otherwise, you can use "onload" instead of "r...

62
Votes
Published 15 Apr, 2022
Javascript - How can I send data via Websocket from a VSCode extension

used ws package, which sadly is not in ES6 module format but otherwise does its job.

5
Votes
Published 15 Apr, 2022
Javascript - Component not updating after useEffect call

Since you call get(), you're only getting the data once. If the data is updated after that, your setCloudUserMachineList won't be updated. If you want to listen for updates to the data, use onSnapshot...

101
Votes
Published 15 Apr, 2022
Javascript - Nuxt image keeps breaking on page change

You can check my previous answer here: https://stackoverflow.com/a/67705541/8816585 This may help export default { publicRuntimeConfig: { baseUrl: process.env.BASE_URL, }, } Otherwise, this c...

74
Votes
Published 15 Apr, 2022
Javascript - Yet again, CSS being problematic again

To fix header you need to set its height to fit content, so it will be over your grid even if you change it later: .headerDisplay { width: 100%; height: content-fit; /* previous: 76.8px */...

58
Votes
Published 15 Apr, 2022
Javascript - array.find(name) returns TypeError name is not a function - Javascript

This is because find takes a function as its argument—not a string. If you wanted to use it here, you'd need to supply a function, such as (s) => s === 'BananaBoat', as the argument. The function you...