Relative Content

Tag Archive for javascriptreactjsreact-hooks

Please fix this broken clock

This component tries to set the ’s CSS class to “night” during the time from midnight to six hours in the morning, and “day” at all other times.’
Here is the code:

Component unmounting causing property to reset

I am making a Task application for myself to improve my workflow. I had gotten around to introducing a timer to the tasks which upon reaching 0 sets the task as overdue. Everything looked fine until I realised the timer disappears when the component unmounts and remounts (due to a filtering process I use). I am self teaching myself react and am quite new to it. Everything has been going pretty smooth but I have been stuck on this roadbump for a while now because of how much state is actually handling the Timer.

There was a problem configuring the counter delay

There is a delay state variable controlled by a slider, but its value is not used.
Pass the delay value to your custom useCounter Hook, and change the useCounter Hook to use the passed delay instead of hardcoding 1000 ms.
Here is the code:

Modal not Closing After Response in React

I’m using useImperativeHandle and ref to let the parent have access to some functions.
I’m wondering why the modal here is not closing? I tried to place alert and console.log and it works but the setIsEditOpen() and setIsDeleteOpen() is not working inside the closeModals.

Why is the ternary operator not working in React?

This is an exercise from https://react.dev/learn/choosing-the-state-structure editable travel snack list. Why is React not allowing ternary operations on state variables. Could not find any specific reason.

How to Prevent Infinite Loop When Prop Function Runs in useEffect

I have parent and child components, and I pass a function from the parent to the child component as a prop. I call this prop function inside useEffect in the child component. ESLint warns me to add that function to the dependency array. However, when I add the prop function to the dependency array, it creates an infinite loop. I also tried using useCallback, but the ESLint warning persists, and adding the prop function to the dependency array still results in an infinite loop. While I can disable the warning, I want to understand the correct way to implement this scenario. Below is the useEffect code snippet, and I will upload both the parent and child code. Thank You