Questions tagged [react-custom-hooks]
146 questions
0
votes
1 answer
Resize image React custom hook
I have a function that resizes the image uploaded by the user which is stored in state and will be sent to the backend.
const [file, setFile] = useState(null)
function dataURLtoFile(dataurl, filename) {
let arr = dataurl.split(','), mime =…

Weber Chang
- 45
- 1
- 7
0
votes
1 answer
isLoading not working when changing state in custom hook
I am using a custom useFetch function, the isLoading function is working if the window reloads but when i change the state with useState hooks, the custom hooks works but isLoading is not working.
-
const [url, setUrl] = useState('/api')
const…

Alucard
- 58
- 5
0
votes
1 answer
Custom Hook argument not being read on React
So, I'm getting the following error when trying to submit a form on React that uses a custom hook:
Uncaught (in promise) TypeError: Cannot read properties of undefined
(reading 'url') at sendRequest (use-http.js:5:1)
Inside the form component, I…

Lucas Vidal
- 1
- 1
0
votes
1 answer
Is there a way to make a custom hook modify a global state on any call?
This is my custom hook:
function useFetch({url = '', method = 'get', body}) {
const [data, setData] = useState(null);
useEffect(() => {
try {
(async () => {
const data = await fetch[method](url, body);
setData(data);
…

Guido Glielmi
- 73
- 1
- 5
0
votes
1 answer
Infinity loop when using custom hook and reducer
I have infinity loop when using custom hook and reducer in React Hook. Custom hook has been infinity loop when moving dispatch setLoading into async function. But when I calling dispatch action out of async function scope, I have related issue with…

Trung Phan
- 1
- 1
- 1
0
votes
1 answer
React custom hook's return value changes and yet the component uses the initial return value
I have created a custom hook that dynamically detects and returns the system color theme.
The custom hook correctly detects every change and sets the value accordingly.
But the component that uses the custom hook always shows the initial value…
0
votes
0 answers
issue when importing use custom hook library
I am getting an invalid hook call error, can anyone help me to solve this! when importing a file from the package it shows the below error, but when using the same file in project dir it doesn't throw an error.
error
react.development.js:1465…

Mahesh M
- 1
- 1
0
votes
1 answer
Custom hook in React JS : arguments not updating after rerender
I have a date range filter in which when submitted, it will update new values of dateStart and dateEnd using setDateStart and setDateEnd then it will pass down the new values to my useCollection custom hook. Why is it that when it rerenders, the…

emdee5566
- 61
- 7
0
votes
3 answers
pass function as parameter to custom hooks
I am trying to pass a function as a parameter to custom hooks I created. The file that uses the hooks and it is it self a custom hook is this:
export const MainStore = () => {
...
const checkForRefreshTokenUpdate = async () => {
...
}
…

billysk
- 137
- 1
- 13
0
votes
0 answers
Error: Element type is invalid: expected a string (for built-in components) or a class/function with custom hooks
I have a custom hook 'useLogout' that is simple:
import { signOut } from "firebase/auth";
import { useState } from "react";
import { projectAuth } from "../firebase/config";
export const useLogout = () => {
const [error, setError] =…

user3238216
- 13
- 5
0
votes
1 answer
Can someone explain me how custom hooks get the data and in depth flow of custom hooks
//use Input HOOK
I want to know that how this custom hook work
import { useState } from "react";
export default initialValue => {
const [value, setValue] = useState(initialValue);
return {
value,
onChange: event => {
…

Saurabh Suman
- 11
- 2
0
votes
2 answers
Question regarding useToggle(custom hook) vs useState hook in react
Below code is a custom Hook called useToggle from a website, it's defined as a custom hook that can be useful when showing/hiding a modal but I don't understand why to go through such code for such a simple feature. Isn't it better to just use…

Un Jin Jang
- 45
- 5
0
votes
1 answer
Custom hook that is called in two components, a father and a child, doesn't update in the father
folks!
I created a custom hook that is called two times, in a father component and also in a child component, the problem is that when the state of the hook changes the child is rendered, but the father component is not updated.
I'm breaking any…

Mauricio Etchevest
- 101
- 2
- 6
0
votes
1 answer
Not updating useState() custom hook when I use setState(somedata)
code
import React from "react";
import useUsersData from "./useUsersData";
export const User = ({ _id, name, age, email }) => {
const [userData, setUserData] = useUsersData();
const handleDelete = (id) => {
const proceed = window.confirm("Are you…

kishor sutradhar
- 31
- 3
0
votes
1 answer
Observables-hooks How to to subscribe only on click
I am an angular dev who is new to React. I use observables to manage all my states as that is what I am familiar with. I am trying to figure out the best way to write a custom observable hook that only subscribes when the user clicks a button
I am…

Isidbigi
- 5
- 1
- 4