Questions tagged [react-hooks]
React Hooks are a feature that allows developers to use state(s) and other React component lifecycle features without writing a class-based component.
react-hooks
30,895
questions
0
votes
1
answer
14
views
Why is the array I'm using with useState seem to be one state behind when I log it to the console? [duplicate]
I am passing data from a child component to the app (parent) component, and in the app component I am adding this data to an existing array with the use of state. When I console.log this array, it ...
0
votes
1
answer
24
views
The input in searchbar disappears when i click on any other space/part of the browser of when i click tab button
import React, { useState, useEffect, useRef } from "react";
import { useNavigate } from "react-router-dom";
import axios from "axios";
import Autocomplete from "@mui/...
0
votes
1
answer
22
views
How to stop the sound player when I move to next screen
I want to stop the sound player whenever I move to next screen in app.
const [shallPlay, setPlay] = useState(true);
useEffect(() =\> {
if (shallPlay) {
try {
SoundPlayer.playSoundFile("...
1
vote
0
answers
19
views
ChatID not defined
I am working on chat app(client side). After fetching the chats I try to click on one of them and when I try to click the chat I want to assign the id of that chat to a useState variable so I can use ...
1
vote
1
answer
17
views
UseContext behavior for deeply nested state changes
I want to understand how React behaves when useContext is used in a component.
Let's say I have a top level context called appContext, that has a nested object structure like
{ key1: value1, key2: { ...
1
vote
0
answers
14
views
"Error: useLocalStorage is a client-only hook" in next js 14
"useLocalStorage" is a client only hook
I'm using useLocalStorage hook from @uidotdev/usehooks. Even though HomePage.tsx file is set to "use client", I'm getting the following ...
0
votes
1
answer
29
views
If I store a function in a reference object, does it hold its value in re-renders?
I was going through this exercise in React documentation and encountered an exercise where we need to add a condition inside Effect. Challenge 2 of 5
I was thinking if we could do it without Effect ...
0
votes
0
answers
14
views
How can I fix react hooks in a React SSR project?
I try to migrate an existing project in js using express and ejs to render templates. I used react and react-dom. But the issues are that hooks and onChange don't work. I'm going to share the client ...
0
votes
0
answers
14
views
How to use useEffectEvent in StackBlitz? [closed]
I am not able to use useEffectEvent in StackBlitz. Any required dependency to upload or other steps to do so?
0
votes
1
answer
18
views
NextJS 14 / React 18 post upgrade error: TypeError: can't access property "useState", dispatcher is null
I'm in a NextJS app that I've recently upgraded from NextJS 12 to 14, and upgraded React from 16 to 18... plus a bunch of other libraries. It's been a trek, and all the things are upgraded.
I am ...
0
votes
1
answer
21
views
Next.js: Passing Props through component with a <form>
I am learning Nextjs and i need to pass a variable through a form component, and then further through its server action component. (i think this is called prop drilling and i dont know if theres a ...
0
votes
0
answers
14
views
Minified React error #321 on Lazy Loaded Components
I have a react.js app which is added to our clients' websites as a widget. The clients' websites can be built on any tool e.g. wordress / angular / react etc.
We've two types of widgets search and ...
0
votes
1
answer
23
views
Value not being passed to addStoreId [closed]
Although the expected value is being retrieved by the retrieveStoreId method (as checked through logging the result of the function call), updating storeId state through context method addStoreId is ...
-1
votes
1
answer
13
views
React Component Redirects to /signin before accessToken updates [duplicate]
I'm working on a React application where I need to ensure that users are authenticated before they can access certain routes. I have a RequireAuthN component that is supposed to redirect ...
3
votes
1
answer
49
views
How to do looping infinite scroll in react? [ NOT PAGINATION ]
I saw this cool effect in one website where the scroll reaches the end it starts again seamlessly from the beginning. and if you scroll back up it goes to landing section.
I was curious and tried to ...