react-hooks Questions

5

Solved

I want to have an input whose width adapts to fit its content. I'm trying to implement this answer to a similar question, but using React: import React, { useState } from 'react'; export default (...
Ankney asked 25/11, 2020 at 19:31

3

Solved

const [active, setActive] = useState(false); const onActiveChanged = useCallback( isActive => () => { // do something setActive(isActive); }, [setActive], // or just [] is okay? ); ...
Pallette asked 18/4, 2019 at 1:59

6

Solved

I'm new to React and trying to make a loading/greeting page that navigates on to the next after a few seconds of being shown. In React Router v6, we have the useNavigate() hook to allow you to cont...

5

Solved

I'm using the useHover() react hook defined in this recipe. The hook returns a ref and a boolean indicating whether the user is currently hovering over element identified by this ref. It can be use...
Antichrist asked 17/2, 2020 at 21:32

11

Solved

Now I'm building the application using React.js. All pages are working excepting of auth page. After logging successfully, it should bring the user to the home page but it was broken, and showed th...
Weiner asked 31/10, 2022 at 15:9

6

I'm making an authentication system and after backend redirects me to the frontend page I'm making API request for userData and I'm saving that data to localStorage. Then I'm trying to load Spinner...
Ursuline asked 12/4, 2020 at 21:13

4

Solved

Can useMemo be used just to avoid extra referential equality checking code/vars when setting state during a render? Example: useMemo with a setState during render taken from this rare documented ...
Alible asked 25/9, 2019 at 15:46

3

Solved

I'm trying to use React hooks to fetch some data and display it, but am getting an error: function App() { const [user, setUser] = React.useState(null); React.useEffect(fetch('https://rand...
Waggish asked 11/11, 2018 at 6:18

3

Solved

As https://github.com/remix-run/react-router/issues/8139 is finished and we got useBlocker in v6, did anyone got it to work? This is what I got so far and pretty much I'm stuck with error I quite d...
Misjudge asked 16/1, 2023 at 13:50

7

Solved

I'm using MUI library to create my React Js app. Here I'm using the controlled Text Field component to create a simple search UI. But there is something strange. The Text Field component loses focu...
Leech asked 30/11, 2021 at 4:27

3

Solved

If you try to pass functional (non react class) component to Animated.createAnimatedComponent it throws an error that says Stateless functional components are invalid as children of createAnimat...
Acroter asked 5/8, 2019 at 13:14

4

Package rn-fetch-blob contains invalid configuration: "dependency.hooks" is not allowed. Please verify it's properly linked using "react-native config" command and contact the p...
Kawai asked 10/8, 2022 at 5:58

7

As we know, we cannot use LocalStorage in React Native. I try to create a useAsyncStorage custom hook instead, which do same function as LocalStorage custome hook in react to store the data in mobi...
Enterotomy asked 16/8, 2020 at 2:19

18

I was trying React Query and got this at the start of my React app. import React from 'react' import { useQuery } from "react-query"; const fetchPanets = async () => { const result...
Lissner asked 6/1, 2021 at 4:25

1

I'm getting this error when testing a component that uses react query custom hook: " No QueryClient set, use QueryClientProvider to set one " this is my hook: export default () => { c...

8

I'm checking if a component is unmounted, in order to avoid calling state update functions. This is the first option, and it works const ref = useRef(false) useEffect(() => { ref.current = t...
Bikol asked 21/11, 2019 at 16:17

6

Consider I have a custom hook that uses one or more refs to DOM elements, I see two distinct ways how to write/use a hook like that (and I know there are probably even more nuances – e. g. ca...
Ber asked 13/3, 2021 at 15:52

5

Solved

I've a series of user data elements which I'm collecting inside a React component using hooks. const [mobile, setMobile] = useState(''); const [username, setUsername] = useState(''); const [email,...
Wamsley asked 19/1, 2020 at 20:3

9

Solved

I'm still getting my head around react hooks but struggling to see what I'm doing wrong here. I have a component for resizing panels, onmousedown of an edge I update a value on state then have an e...
Neogaea asked 20/3, 2019 at 16:4

4

Solved

I'm working on something in react and have encountered a challenge I'm not being able to solve myself. I've searched here and others places and I found topics with similar titles but didn't have an...
Shrum asked 26/5, 2021 at 5:5

5

Solved

I have tried what is written on their @tawk.to/tawk-messenger-react plugin docs? I have made a component like /components/Chat.js import TawkMessengerReact from "@tawk.to/tawk-messenger-react&...
Bikol asked 13/3, 2022 at 15:8

4

Solved

Why can't useEffect() use async-await? const Home: React.FC = () => { useEffect(async () => { console.log(await ecc.randomKey()) }, []) return ( ... The error I get is Argument of...
Callisthenics asked 28/7, 2019 at 7:49

3

In my React/TypeScript app that uses Formik, I am getting the error Object is possibly 'null'. TS2531 125 | <Modal.Footer> > 126 | <Button variant="primary" type="subm...
Resonant asked 10/2, 2021 at 21:17

3

Solved

I am trying to mock react-router-dom in one of my test cases so that the useHistory hook will function in my tests. I decide to use jest.mock to mock the entire module, and jest.requireActual to pr...
Selfdenial asked 7/7, 2020 at 12:7

4

Solved

I have a cutom hook that makes an API call on mount and handles state (isLoading, isError, data, refetch); The hook is quite simple: const useFetch = (endpoint, options) => { const [data, setD...
Peterson asked 28/7, 2022 at 9:14

© 2022 - 2024 — McMap. All rights reserved.