Questions tagged [react-custom-hooks]
146 questions
0
votes
0 answers
Advice: React Custom Hook with onClick and inline access to response
I've started using custom hook's in React, creating the following:
export function useLazyHook({ onCompleted, onError }) {
// Apollo
const client = useApolloClient()
/**
* Use State
*/
const [loading, setLoading] =…

HireLee
- 561
- 1
- 9
- 25
0
votes
1 answer
How to use Apollo useMutation in custom React hook
I'm still having issues with wrapping my head around Hooks. I constantly run into issues where it complains I'm doing an Invalid hook call.
This time, it's when trying to use the useMutation hook from Apollo inside a custom hook.
I'd appreciate if…

Paul van den Dool
- 3,020
- 3
- 20
- 44
0
votes
0 answers
React Context; useReducer Pattern: Can/Should properties on initialState have functions to update initialState?
I have a custom hook which I am trying to move into the context/reducer pattern:
import { sortDateStrings } from '@/Utils/SortDateStrings'
function useDiscounts ({ data }) {
const [effectiveDates] = useState(data.effectiveDates || [])
…

Antonio Pavicevac-Ortiz
- 7,239
- 17
- 68
- 141
0
votes
1 answer
custom hook returns wrong value
I made a custom hook as my intersection observer but I'm getting false and true state at the same time and twice!, first false(twice) and second true(twice) why is this happening? why state changes itself? state must be true because h3 is 100%…

muller
- 41
- 8
0
votes
1 answer
Custom hook fires every render
I want to run a callback when a component mounts, but not on each render. Using useEffect and an empty dependency array created warnings. I read on a different thread which I now can't find that this can be achieved by creating a custom hook:
import…

Laurence Summers
- 201
- 1
- 3
- 14
0
votes
1 answer
Unable to pass down state using react context
I am trying to use React Context successfully but I a have had a lot of trouble with it. I can't even successfully pass anything one level to the provider's immediate children, as a result all I am getting at this stage is "x is undefined" errors in…

Aueisbiejei3i939
- 91
- 1
- 10
0
votes
1 answer
How to update value of input values with useRef in a map function?
I have decided to use refs to hook into the inputs,
In fact I created a custom hook to consume the fetched data and then make the refs!
function useCreateRefFromProfileDataFromApi(profileDataFromApi) {
const [profileData, setProfileData] =…

Antonio Pavicevac-Ortiz
- 7,239
- 17
- 68
- 141
-1
votes
0 answers
Can I call custom hooks inside the return()/callback?
I was curious about if it's possible to call a custom hook as and when required.
Let's say I have a simple custom hook - useLogToConsole() which just logs 'Hello World' to the console. Now I know I can call this hook on top of my component. But I'd…

JAY PRAKASH
- 7
- 4
-1
votes
1 answer
Access redux toolkit dispatch in custom hook with nextjs app
I have created a custom hook in my nextjs app, where i create an axios instance. It looks as follows:
import axios from 'axios';
import { useRouter } from 'next/router'
import { useAppDispatch } from '../store/hooks'
import { stopLoading } from…

Marcus
- 29
- 1
- 5
-1
votes
1 answer
How much it is mandatory to use state pattern i.e. mobx or redux in developing applications
I have seen it is becoming mandatory to use state pattern i.e mobx or rudux etc for building any react application. I am concerned that how much it is necessary to use these patterns. like if i have an application and have some pages in it each one…

Jahangir Hussain
- 391
- 1
- 4
- 10
-1
votes
1 answer
Custom hook to add query params always renders the component the using it when the location is changed. Used react-router-dom
Problem
I have a custom hook which is used for updating the query string in the url with the help of location and history from 'react-router-dom'. So in the components whenever I want to add a new query I use this hook. In this custom hook I used…

praveen guda
- 97
- 2
- 10