I hope you are doing fine. I was surprised by some code that doesn’t work anymore with typescript: Here is my minimal reproduction scenario: The goal is to create a generic function with two types, when the second corresponds to a selected value by an optional parameter. The issue is that it is like whe…
Tag: javascript
Access React state of function enclosed inside useRef doesn’t update
I’m trying to access React state inside a function enclosed inside of useRef. However, even with a helper function bound to App to access the state, the state never updates inside of the useRef function. Answer The argument passed to useRef is only considered when the component mounts. Only at that time…
How do I add to existing data with findByIdAndUpdate instead of updating the data entirely
This is my object schema I am trying to update the number of votes like this Let’s say the original amount of votes is 1, and the requested amount of votes is 5. The put request will update the amount of votes to be 5. Instead I would like to add the requested amount of votes on top of the
reformatting json file to have identifying attribute and array to accomodate for sub-objects
I am trying to reformat some relatively unstructured json to fit my needs, where I want each object to have a ‘name’ attribute as well as a ‘children’ array for sub-objects. I have a json file that looks like below: I would like to format it to be something like this: How would I be ab…
How to get a user’s keypair from their public key only (Solana)?
I’m making a dApp and I want to add a button where a user (the one with their wallet connected) can send exactly 0.01 SOL to another user. I already wrote the function in my Rust program and after testing it with anchor test it seems to be working when I use my own personal wallet’s Keypair to sig…
Javascript replace a capture group to uppercase (not a duplicate)
I am aware of Replace a Regex capture group with uppercase in Javascript That is for replacing the entire match and not a () match. Here is my problem: This returns the entire tag as uppercase and not the actual text in (.*). I just want to replace the span tag with just the uppercase of the innertext. There …
MongoDB FIND method does not work in code
so when I try to find items in a collection through the console using the method db.DB_NAME.find({ x: y }, it works just fine. However, when trying to do the same in the code, it does not work. Perhaps it is worthy mentioning that the method findOne works great within the code. Consulting through the console …
How to create an array in the GraphQL’s argumment as GraphQL Code First Approach
In GraphQL Code First Approach I am trying to pass the same argumment for createUser in createManyUser but I want to pass it as an array to create many users at once. I searched a lot but couldn’t find it in GraphQL Code First Approach. The Code Answer You can’t just put the args options in an arr…
Store large amount of data in Javascript
Im receiving some file chunks in bytes format from my server and im collecting them into one variable in my frontend to download it later. And I can’t change my server conception (receiving a file sliced into chunks). My problem is that if the file is heavy (from 500MB), my variable length is starting t…
Fetch data is shown in console.log, but not in HTML TAG
I’m trying to fetch a JSON data from our server and then inserting it in a <script> TAG in client-side. See below: The problem is: when I console.log(data.imports), it shows me the fetched data, but the <script> TAG looks like this: What it looks strange for me is when I use JSON.stringify(d…