react-hooks Questions

6

Solved

I want to use a state variable (value) when a modal is closed. However, any changes made to the state variable while the modal is open are not observed in the handler. I don't understand why it doe...
Freudian asked 13/9, 2022 at 4:0

4

I've a formik form in a component that I'd want to reuse. In order to do that I need to listen to the form values changes in order to call two functions, getFormValues and getFormErrors, that will ...
Dissident asked 23/1, 2022 at 19:28

1

Solved

In React I am using @react-three/fiber for the 3D stuff. There are a lot components that don't support declarative way of doing things and require refs and imperative code (e.g. CameraControls from...
Touristy asked 24/9 at 12:51

4

I am building a chat app and would like to write integration tests using react-testing-library and can not figure out how to mock socket.io-client's socket.on, socket.emit, etc. I tried follow thi...
Bradwell asked 3/10, 2019 at 2:44

3

I am trying to make hover effect with react hooks I wrote function to hover based on some tutorials function useHover() { const [hovered, setHovered] = useState(false); const ref = useRef(nul...
Scrip asked 2/5, 2020 at 16:24

3

Solved

In my React app, I have a custom defined hook that holds a useState value internally, but the custom hook itself does not return any values. If the value of its internal useState changes would this...
Disjuncture asked 11/6, 2022 at 16:15

1

I am building a little local dev/testing/documentation environment for some components which are used across different projects and so want to create them as individual npm packages. Everything was...
Lithea asked 20/5, 2022 at 23:17

3

In the code below, whenever I get new props from the parent, the new props are logged correctly on the console, but the rendered HTML is never updated after the initial render: export default funct...
Pitre asked 24/5, 2022 at 21:43

3

I am facing some errors while rendering at SSR for some URL using renderToString from "react-dom/server" I am getting following error: TypeError: Cannot read property 'length' of undefine...

4

Solved

I'm used to passing functions to useState, so that i don't create unnecessary objects: useState(() => /* create complex obj */) I expected that useRef would work the same way, but the below ret...
Occasionalism asked 11/10, 2022 at 20:36

3

Solved

How i can do memory cleaning by cat.destroy() method when component is dead? const object = useMemo(() => { return new Cat() }, [])
Psalmbook asked 2/3, 2021 at 20:27

5

I have React function component that has a ref on one of its children. The ref is created via useRef. I want to test the component with the shallow renderer. I have to somehow mock the ref to tes...
Melchior asked 5/9, 2019 at 12:51

3

I have a project using React in Strict Mode alongside GraphQL. I updated some packages, and I now get the following error in useEffect containing async calls. useEffect(() => { const loadTags ...
Sheridansherie asked 26/1, 2023 at 6:53

2

Solved

I honestly have no idea what is going on here. I have this code, on first render it should fetch popular repos and set them to the repos state, which should cause a re-render and paint the ne...
Middleweight asked 28/4, 2020 at 20:58

2

I am using react-select for better look on UI, and I have implemented it, Now what I am trying to do is I want to validate that input field when user clicks on Done button (form submit) I am using...

2

I'm trying to pass a ref from a parent component (an EditableCell) to a Child component (Input) and use its .current.focus property when the parent is clicked. I'm using the forwardRef function usi...
Rabaul asked 5/2, 2021 at 8:51

5

Solved

The app displays all photos <Photo> in a grid <PhotoGrid>, then once clicked, a function in <Photo> changes URL with history.push, and Router renders <Single> based on URL u...
Snick asked 6/3, 2021 at 14:44

11

Solved

While trying to install npm install, I am getting below error, how to resolve it? $ npm install npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! Whil...
Nomanomad asked 13/6, 2022 at 1:8

2

Solved

On a react class I would write something like this class Myclass extends React.Component { handleUpdate = info => { //do the update } render() { return ( <SomeMarkup> <SomeComp...
Mirabel asked 28/2, 2019 at 22:3

7

I used react.js Hooks with useState and useEffect, when I scroll-down and the screen comes down Header hides after 250 pixels. Now I want to know how to display Header using the react Hooks when I ...
Alacrity asked 6/10, 2021 at 22:12

7

Solved

The standard way to use a React useState Hook is the following: const [count, setCount] = useState(0); However this const count variable is clearly going to be reassigned to a different primitiv...
Factor asked 14/11, 2019 at 15:12

2

My understanding is that Javascript classes store their methods on the Class prototype and therefore all Class instances use the same function definition in memory when invoking those methods. i.e....
Bamboo asked 15/8, 2020 at 21:5

2

Solved

Here I have code of react table using hooks, and i have struggled on task where I need to set all rows and subrows expanded by default when i open the page, I have tried several solutions, but all ...
Misfire asked 5/2, 2020 at 11:10

3

Beginner here, but finding this quite tricky. So some help would be appreciated! I want to have users filter through some options. Those filters should be reflected in the URL. e.g. : http://localh...
Airport asked 28/10, 2022 at 10:21

2

I'm starting to use hooks in React and I got stuck, when I realized I would need an array of hooks to solve my problem. But according to the Rules of Hooks Only Call Hooks at the Top Level I'm no...
Glosseme asked 8/1, 2021 at 13:58

© 2022 - 2024 — McMap. All rights reserved.