October 22, 2024
Chicago 12, Melborne City, USA
javascript

img src is in array of object, using async await but images do not appear in react app

const [decks, setDecks] = useState(); const [loading, setLoading] = useState(true); function getCardImage(decks){ decks.map(async(deck)=>{ deck.img = await MagicApi.getCardImage(deck.commander); }) return decks; } useEffect(()=>{ const gettingDecks = async (userInfo) => { const res = await UserApi.getDecks(userInfo); const res2 = await getCardImage(res); setDecks(res2); setLoading(false); } gettingDecks({id}) },[]); if(loading) return <div><h3>Fetching Your Commander Decks...</h3></div> console.log(decks) return( <Row> {decks.map(deck =>

Read More
javascript

Angular: Await method do not execute the route.navigate() present inside the setTimeout?

I faced a weird issue when I am integrating a async routing above the await method. If I remove the await method, I can see the routing id working as expected. Below I am giving the code sample. async deleteApplication() { const confirm = await this._prompt.showDelteConfirm(this.application.name); if (confirm) { // Block 1 start setTimeout(async ()

Read More
javascript

React testing library not work with react router v6

I have several unit tests that test form validation for my login screen. Example: test("Invalid email renders error", async () => { render(<LoginForm />); // Arrange const emailElement = screen.getByTestId("email"); const passwordElement = screen.getByTestId("password"); const submit = screen.getByTestId("login-button"); // Act await user.type(emailElement, "invalid"); await user.type(passwordElement, "1234567890"); fireEvent.click(submit); // Assert await waitFor(() => { expect(screen.getByText("Invalid email

Read More
javascript

How to go to the First slide when reaching the last slide?

I have this slider that works just fine. However, when it reaches the last slide I want it to keep moving to the RIGHT and show SLIDE 1. My issue is that once it reaches the last slide it moves to SLIDE 1 but it moves to the LEFT. Can anyone point me in the

Read More
javascript

Hi everybody, how do I add the vercel's analytics function to my project?

I’m basically trying to add the vercel’s analitycs function to my project, but, it simply doesn’t work and i don’t know why. I just followed the instructions in the documentation, but, it doesn’t work. React is installed, the image is my layout.tsx enter image description here You need to sign in to view this answers

Read More
javascript

Trouble using require(); Needing to convert JS file to ES module

When I use require() in my JS file, I get the following error: File is a CommonJS module; it may be converted to an ES module. Why is it so? And how can I use require, ie, convert my JS file into an ES module? I have tried to append "type":"module" to my javascript file,

Read More
javascript

Canvas with webgl becomes broken after some time

I have a page where I use multiple canvases with webgl2 context. When I load or refresh page everything works good (rendering in canvases). But if I go to other tab in browser or switch focus to other app, and then return back to my page some canvases may become broken. In my case "broken"

Read More
javascript

Prisma returning unwanted count

Doing the query below the Prisma result returns a unwanted "count" property into likes object. We can see that the _count operator is not used anywhere. I tried to change the count to false, but it keeps being returned. How can I disable this? const user = await prisma.user.findUnique({ where: { id: id }, select:

Read More
javascript

exiftool-vendored: `extractBinaryTagToBuffer` Fails Unexpectedly

I want to read XMP data from PDFs in JavaScript: const { exiftool } = require('exiftool-vendored'); const fs = require('fs'); async function extractXMPData(filename) { try { const buffer = await exiftool.extractBinaryTagToBuffer('XMP', filename); console.log(buffer.toString()); } catch (error) { console.error('Error reading XMP data:', error); } // Close the exiftool instance to free resources await exiftool.end(); } const

Read More
javascript

Can't load images from local files in React, React is trying to pull image from proxy?

I am currently building a small react webpage and the component I’m building returns one of two images based on whether a certain variable is null or not (it is supposed to hold the link to an image after an api request is made, but starts null). When that link isn’t available the code is

Read More