1,312 questions
Best practices
1
vote
4
replies
62
views
Where to manage the state of individual items in a list
So, being used other reactive frameworks I'm now starting to learn and work with React. I'm building a simple exercise and I'm struggling with the way State is managed in React, I'll already have ...
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
211
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
75
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
62
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
76
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
794
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
95
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 ...