Questions tagged [react-custom-hooks]
146 questions
0
votes
1 answer
A value increments twice onKeyDown
I am trying to make a Tetris game, I have added move functionality where onKeyDown a block would either move left or right.
some game components
The move…

BlackC4t
- 71
- 7
0
votes
0 answers
React custom hooks - run on every rerender
I was working with someone else's code and there was custom hook:
const {
data, loading,
count, mutate
} = useSomeoneHook(filter, page, pageSize);
/* file with hook */
const useSomeoneHook = (filter, page, pageSize) => {
const…

Patryk
- 29
- 5
0
votes
0 answers
Can I rerun a hook only if parameters changed?
I have a react component that uses some hooks. The component will call hooks with parameters and get a value back.
Is there a way to only execute the hook if the parameter is different from the previous value just like how we can use React.memo() on…

user5507535
- 1,580
- 1
- 18
- 39
0
votes
2 answers
useEffect inside custom hooks
I know that in case of react components the function inside useEffect will run after the component has been rendered. When exactly does it run if the useEffect is inside a custom hook?
As a more generic question when do the codes inside a custom…

Erfan Mirhoseini
- 1
- 1
0
votes
0 answers
How to share stateful variables using custom hooks without useContext
I have a simple custom hook called useFlightData that has a couple of stateful objects created using useState. Here is the code.
export const useFlightData = () => {
const [userFlightChoices, setUserFlightChoices] = useState(
…

Amos Machora
- 486
- 3
- 12
0
votes
0 answers
react setState async custom hook not working
I want to perform the following action after processing setState asynchronous processing with await.
This is the code I wrote.
react + typescript
custom Hook useAsyncState
import { useState, useRef, useEffect } from 'react';
const useAsyncState =…

고윤태
- 11
- 1
0
votes
1 answer
Using React Hooks inside a function not working
I have a misc.js wherein I have the following function which is meant to be used by several components:
export function loginCheck() {
const dispatch = useDispatch();
const user = useSelector((store) => store.user.currentUser);
!user &&…

elijaveto
- 31
- 2
0
votes
0 answers
setState from custom hook not updating
I got an issue I can't seem to resolve, problem is as follows:
I got a custom hook which opens a modal whenever an event on calendar is clicked.
It also returns the state and setState so that I can manipulate that state from wherever.
const…

ikkako
- 29
- 9
0
votes
1 answer
react hook causes infinite loop
I am new in react and I don't know what happens when i try fetch cause infinite loop
const useDadosSolicitacao = (idSolicitacao: number) => {
const [dadosSolicitacaoDevolucaoAmostra, setDadosSolicitacaoDevolucaoAmostra] =…

Victor
- 5
- 1
- 4
0
votes
0 answers
Create useTransition custom hook using useReducer in react 17 version
I know that useTransition hook was created using a function called flushSync in react 18 version.
Can't I use this as a custom hook in react 17 version?
Due to my lack of knowledge, I haven't tried it.

Fourier
- 1
0
votes
0 answers
Response mismatch with fetch API in React
I am using custom hook that wraps up fetch api to pull data from endpoints. However, response of totally unrelated request are being mismatched, meaning response of one api is being injected into another request:
This is how I am making use of…

Ganesh Khadka
- 61
- 6
0
votes
0 answers
Custom hook not triggered on rerender
I have a component that looks like this:
export const DatePickerInput = ({
label,
onChange,
defaultSelected,
fromDate,
placeholder,
hideLabel,
className,
valuesInitialized,
setValueInitialized,
}:…

Leff
- 1,968
- 24
- 97
- 201
0
votes
1 answer
CustomHook with multiple functions doesn't work
I am not sure why this customhook doesn't work , I am trying to make a payment Integration to my website but it doesn't return the frame to the other component so i can get the link , here is the code
import React , {useState} from 'react'
import {…

geniar99s
- 31
- 7
0
votes
1 answer
React: update state only once, when another state reaches certain value
Here's my code https://codesandbox.io/s/heuristic-cannon-lvse23?file=/src/App.js
import { useEffect, useState } from "react";
import "./styles.css";
function useAsyncState() {
const [status, setStatus] = useState("idle");
function…

dmzkrsk
- 2,011
- 2
- 20
- 30
0
votes
0 answers
How to effectively refresh the data in a custom hook using react-infinite-scroll-component when an item is deleted?
I am using a custom hook useInfiniteFetchSearch to fetch and search data for a infinite scroll component built using react-infinite-scroll-component.
The hook makes an API call and sets the data in the state using setData. Currently, I am using…

Abhilash
- 43
- 1
- 8