react-hooks Questions

2

Solved

This is the useEffect code in the React component. import { useSession } from '@supabase/auth-helpers-react' const session = useSession() useEffect(() => { if (session) { console.debug('sta...
Lager asked 13/6, 2023 at 10:56

2

In my func component I am trying to use history.push in this way: import React, { useEffect } from 'react'; import { useHistory } from 'react-router-dom'; interface Props { question: Question; s...
Amigo asked 8/7, 2020 at 10:0

2

I have my app inside a Strict Mode and it makes it difficult to run with my useEffect(). It basically logs all my values twice in the console which is not the result I want to achieve. useEffect((...
Grebe asked 20/7, 2022 at 9:35

6

Solved

Using hooks, If I call setState with the same value as the state, will it rerender the component? If yes, how can I avoid that? e.g. const [state, setState] = useState(foo) ... // any where in ...
Macaluso asked 26/12, 2019 at 14:46

8

Solved

There's a bunch of articles out there that show how Redux can be replaced with context and hooks (see this one from Kent Dodds, for instance). The basic idea is to make your global state available ...
Rendezvous asked 14/1, 2020 at 20:46

4

Solved

I make an API call. It appears React goes ahead to build a table without the data, thus throwing error of Uncaught TypeError: Cannot read property 'map' of undefined Here's what I'm doing useE...
Clink asked 20/11, 2019 at 14:35

6

Solved

I'm fetching data from a weather api using useEffect hook and declaring the dependency correctly as well. My state is still not being updated and I get errors in my render function because of that....
Ringnecked asked 30/7, 2019 at 2:22

3

Solved

In my React game, I use a React library called Formik for a form. In it, you set the initial values for the form like this: <Formik initialValues={{ characterClasses: ["1", "3&q...
Gorgon asked 17/7, 2020 at 18:9

4

Solved

I am new to context API and trying to get my code to work. I am getting error: Uncaught TypeError: Object is not iterable (cannot read property Symbol(Symbol.iterator)) Would some of you good peo...
Cardialgia asked 12/2, 2022 at 10:11

11

Solved

I don't understand why is when I use setTimeout function my react component start to infinite console.log. Everything is working, but PC start to lag as hell. Some people saying that function in ti...
Langan asked 31/10, 2018 at 19:9

1

I am trying to update my React application to use MVVM as an architecture pattern. I initially built it out with Hooks and Redux. I've come to find out that every resource I've found uses classes i...
Gnat asked 1/7, 2020 at 20:38

11

Solved

I am reading about React useState() and useRef() at "Hooks FAQ" and I got confused about some of the use cases that seem to have a solution with useRef and useState at the same time, and ...
Diminish asked 5/6, 2019 at 7:23

6

As the React documentation mentions: If the ref callback is defined as an inline function, it will get called twice during updates, first with null and then again with the DOM element. This is bec...
Pt asked 4/4, 2023 at 8:41

8

Solved

when in the development environment, my app works just fine. When in the production environment it crashes with the error: Uncaught TypeError: (0 , _react.useEffect) is not a function It happens ...
Repatriate asked 21/4, 2020 at 16:47

28

Solved

I'm trying to use the throttle method from lodash in a functional component, e.g.: const App = () => { const [value, setValue] = useState(0) useEffect(throttle(() => console.log(value), 100...
Intoxicate asked 13/2, 2019 at 9:14

0

In order to understand why components are re-renders without apparent reason, I started the profiler. I can see that my component re-renders because of Hook 18: So to understand what this mean, I ...
Mat asked 23/5, 2023 at 9:37

2

Solved

import React from "react"; import Users from "./components/Users"; import Contact from "./components/Contact"; import About from "./components/About"; const routes = { "/": () => <Users /&gt...
Seem asked 13/6, 2020 at 7:18

13

Solved

useHistory giving this error: Failed to compile ./src/pages/UserForm/_UserForm.js Attempted import error: 'useHistory' is not exported from 'react-router-dom'. This error occurred during the build...
Shroudlaid asked 12/7, 2020 at 12:47

2

When fetching state from an API with Zustand in a useEffect function what is the best practice for doing that? Right now I am using it very simply: export interface ModeState{ modes: Mode[]; fetc...
Adalie asked 14/7, 2022 at 19:31

2

Solved

I want to test a custom hook which was implemented as an helping function for code reuse with other hooks. It's calling useDispatch and useSelector in its implementation, along with saving data in ...

5

Solved

Actually, I try to validate the form and Stucked to validate the password and confirm the password.. is there any property in useForm to validate the password and show a message in react hook form...
Tallahassee asked 25/12, 2021 at 15:19

3

Solved

Given that I can't test internals directly with react-testing-library, how would I go about testing a component that uses react-select? For instance, if I have a conditional render based on the val...

4

Solved

I have hook useInterval which download data every 10 seconds automaticaly, however I have also button which can manually download data in every moment. I'm struggling to restart interval timer when...
Haemorrhage asked 4/2, 2021 at 9:55

3

Solved

I have a mini shopping cart application that uses useState. I now want to refactor the application's state to be managed by useReducer and continue to persist data with localStorage. I'm having tro...
Vachel asked 27/10, 2020 at 1:11

2

Example is a functional component in which I am rendering a div conditionally. I want this div to fade-in when rendered conditionally and fade-out vice versa. For that, I have maintained two local ...
Centrifugate asked 25/4, 2020 at 16:32

© 2022 - 2024 — McMap. All rights reserved.