1,311 questions
0 votes
2 answers
160 views
Updating stateful list in React based on another stateful variable
Here are two React components: function MainScreen() { const [stopwatches, setStopwatches] = useState([ new Stopwatch('A'), new Stopwatch('B') ]); const [selectedStopwatchIndex, ...
2 votes
1 answer
115 views
Component Inside another state doesn't rerender when state changes
The below block of code works. Component rerenders when state changes from parent (MainBox) export function MainBox(){ const [valuestate, setvalueState] = useState() return( <div&...
2 votes
2 answers
209 views
In React, why does useRef need .current but useState doesn't?
Ref interface: // create const count = useRef(0); // update (does not trigger render) count.current = 5; // access console.log(count.current); State variable interface: //create const [count, ...
0 votes
1 answer
74 views
Why doesn't useState update correctly in my custom useFetch hook?
I'm trying to write a custom React hook that fetches data. It seems to work partially — but loading goes false before data is set, and error is never set even when a request fails. import { useState, ...
0 votes
2 answers
61 views
React Input loses focus after state update
I am trying to build a custom form component. In this I use inertiajs useForm hook to automatically load the data into a state (similar to react-use-form). But my problem is, that everytime i type a ...
0 votes
2 answers
81 views
Not updating state variable which is array of objects
perms is an array of objects. Each object is: { catg: 'Catg1' serv: ->array of serv objects { checked: false, desc: 'Serv 1' } } On button click, based on ...
-1 votes
1 answer
45 views
Why does the prop of the child component change if the parent component has no change?
I have a parent component where I use state to control the visibility of a child component. If I use a button to open a modal it works, but when I change the state in useEffect child prop = false ...
2 votes
1 answer
74 views
setState function not recognized as function
In my React Native app, I'm having a problem where the setState function is not being recognized as a function. I already inserted the context provider on the App root page and exported the context ...
-1 votes
1 answer
59 views
React - component state variable value not updated when used in handler, which passed to child
I try to make some kind of infinite scroll Here is my CodeSandbox setup (first approach) To paginate I made some kind of cursor which keeps last loaded item id in after state variable I use that after ...
0 votes
1 answer
778 views
Shadcn/cmdk cannot bind to command input component
I'm trying to compose my own Combobox component using Shadcn ui. In doing this I am using the Command component. I am trying to bind my command input value to React state in Next.js client component ...
0 votes
1 answer
83 views
How to re-render table to reflect input data
I have two files/components: Createrisk.jsx for creating individual risks Tablepage.jsx displays the risks in an MUI Data Grid The problem is Tablepage renders only the attributes from Createrisk ...
1 vote
0 answers
94 views
Re-renders when clicking Copy Clipboard button
I am using monaco-editor and I created a code preview. In the previewer, I want to copy the contents, but everytime I click my copy button, it always rer-renders. What am I missing? or How should I ...
-1 votes
1 answer
56 views
Data Table won't render instantly even after useEffect triggered
I am using DataTables in a NextJS project. I'm getting data from the backend with: const [rows, setLocalRows] = useState([]); useEffect(() => { if (Array.isArray(initialRows)) { setLocalRows(...
0 votes
1 answer
33 views
LocalStorage Value Not Resetting Daily When User Closes the Page
I'm building a React app where I store a boolean value (hasGuessed) in localStorage. This value should reset to false every day at midnight. Currently, I'm using setTimeout to schedule the reset at ...
-1 votes
4 answers
115 views
Attempting to use a loading state to stop undefined data
So I know that the data used in a setState call won't be updated until the next render and have looked up plenty to figure out what to do about that. The best solution I kept finding was to use a ...