Questions tagged [react-custom-hooks]

146 questions
0
votes
1 answer

React. Prevent click events on Double click

Im trying to implement a timer to distinguish between single click and dbl click events so the single click does not fire when dbl clicking. Edit: I should clarify, I want the component to react differently to single/double clicks, the Double click…
Tom
  • 139
  • 1
  • 4
  • 14
0
votes
1 answer

Write a custom hook that compares values

Hello :)) I not familliar with custom hook in React. I have tried simple ones, but example below I don't know how to resole I want write a hook that will work similarly to useState, except that it should update the state only when the new value is…
McKrus
  • 37
  • 2
0
votes
0 answers

React Custom Hook - Problem with getting the updated value of a custom hook

I juste created a custom hook to update a value from a calendar picker, and getting it updated in a Form component. export const useCalendar = (props) => { const [startDate, setStartDate] = useState(""); useEffect(() => { …
Marc Habib
  • 11
  • 2
0
votes
0 answers

Create React custom hook instead of helper function

I created a helper function in my React app to fetch the status after fetching a url: import { useEffect, useState } from 'react'; const fetchStatusCode = (url: string) => { const [data, setData] = useState(null); useEffect(()…
meez
  • 3,783
  • 5
  • 37
  • 91
0
votes
0 answers

Can get the type right in input validation custom hook Typescript

I found this custom hook to validate input values on github https://github.com/WebDevSimplified/useful-custom-react-hooks/blob/main/src/18-useStateWithValidation/StateWithValidationComponent.js import { useState, useCallback } from "react" export…
0
votes
0 answers

React: Custom Hook not passing data to Context hook

I'm triying to pass data from a validator custom hook component to my context. My custom hook checkDB receive LoginData but fails when trying to pass a destructured variable to another function in my context import { useContext, useState } from…
0
votes
1 answer

Encountered two children with the same key when requesting a data from fireabase with onChildAdded

Intro I'm creating a chat application and was trying to get rid of useless messages rerenders in a messages list when requesting them with onValue from firebase (snapshot from onValue was overwriting whole messages list state which caused to a…
0
votes
1 answer

Expose a Custom Hook to Children (children only) in React

I'm not sure the title is correct, so let me try to explain what I'm trying to achieve. Let's say I have a flow in my application that has 3 steps in it, so I create a component (let's call it Stepper) with 3 child components where each child is a…
0
votes
0 answers

What's wrong with my React Custom Hook cleanup function implementation?

I've built plenty of React Custom Hooks before but only recently built my first useFetch custom hook. The code is base on me reading lots of articles on the subject and then implementing my own version. It generally works well except that…
RobertW
  • 226
  • 1
  • 2
  • 10
0
votes
0 answers

Way to invoke function again while not setting different value in state

So I have built app which takes value from input -> set it to the state-> state change triggers functions in useEffect (this part is in custom hook) -> functions fetch data from api -> which triggers functions in useEffect in component to store…
user19786344
0
votes
1 answer

TypeScript: Problem typing a custom Form hook

I know this is gonna be messy and terrible but while I have the TypeScript basics down, I'm having trouble typing the more advanced concepts, particularly typing useReducer hooks. Here's my code with what I have so far, but I understand I have…
0
votes
1 answer

Infinite loop on custom axios Interceptor Hook

I have a custom hook which I have attached an axios interceptor to check if my token is expired. The problem is that it causes an infinite loop on any component I attach it to. I am using this hook on every request that needs authentication. i don't…
louis
  • 422
  • 1
  • 4
  • 14
0
votes
0 answers

Infinite loop inside React JS

So, I found similar issues that were not quite the same and didn't help me understand my problem. I'm building a simple task manager using React and Firebase. I'm fetching data using a custom hook, since different components need to fetch data from…
0
votes
2 answers

The return type of useQuery's data is unknown

I made a custom Hook called useRequest using react-query. Through him, a custom Hook called useUser is created, and in the process, the data type is evaluated as unknown. I tried several methods, but all failed. But data fetching works fine. How can…
김정수
  • 611
  • 4
  • 9
  • 22
0
votes
1 answer

How can I call a custom hook which accepts parameter inside useEffect?

In my component I use a function which I want to extract, it uses some hooks for setting url params. I created a custom hook. function useMyCustomHook() { const history = useHistory(); const location = useLocation(); const locationParams…