320 questions
1
vote
2
answers
2k
views
Child Component Re-renders Due to useFormContext in React Hook Form
I'm experiencing a challenge with React Hook Form where my child component InputX re-renders every time there's an update in the parent component or other parts of the application, despite no changes ...
4
votes
2
answers
6k
views
Sonner toast is not rendering toast on component mount
I want to show a toast when my client side component mounts.
I'm using sonner library to show toast, it's working fine when we use button to show toast.
I make an example app to show the problem. Here ...
-1
votes
2
answers
100
views
React component rerender for only changing class [closed]
I am relatively new to React, and still have not full familiarity with this thing to re-render components every time a state changes.
I understand that re-renders make declarative components possible, ...
0
votes
1
answer
52
views
React Chart.js plugin renders stale data
I am rendering a series of Doughtnut charts with center text rendered via plugin.
While initial render is working as expected, when I implement a client side search and hence re-render the series of ...
3
votes
1
answer
1k
views
componentWillReceiveProps is still working in react 18.2.0
I am working on updating react version to 18.2 from 16.8.6 in one of my projects. After doing the upgrade one of the major warnings that I got in console is regarding the deprecated lifecycle methods ...
0
votes
1
answer
72
views
How to get latest props in componentWillUnmount?
I have a below parent component where I am updating id value to 2 which is a state of parent component and I am rendering the Child component only if id value equals to 1, if I do so Child component ...
0
votes
2
answers
50
views
Why will this code allow for an update of the window width and height when clearly the event listener is removed within the same render cycle?
import React, { useState, useEffect } from 'react';
const WindowSize = () => {
// Add your state and useEffect logic here
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
...
0
votes
1
answer
39
views
Use of conditional boolean in React hook
Following is the doc I am using to learn React Custom Hooks.
Doc Link - https://react.dev/learn/reusing-logic-with-custom-hooks#when-to-use-custom-hooks
In that page, there is a piece of code -
...
2
votes
1
answer
2k
views
Console log in React function components for beginner
My problem
The code is simple. When you switch to any new button, it will log the updated sourceType, then "My Log".
You start off at the posts tab, then you clicked users tab, it will log &...
2
votes
1
answer
224
views
react hooks equivalent of passing a `key` to a component to control its lifecycle
If I have a component:
function MyComponent() {
const state = useState(resetState())
return jsx(state)
}
then I can trigger a state reset by passing a key to MyComponent:
<div>
<...
-2
votes
1
answer
284
views
How do I show details of a loading process while data is loading in useEffect?
When a particular custom React component I have first mounts, it uses useEffect to kick off a long multistep process of loading data that it will then render. The component isn't always rendered, so ...
0
votes
1
answer
58
views
Is returning `true` in shouldComponentUpdate the same as not having shouldComponentUdpate?
In my React Native component, I added an empty shouldComponentUpdate
shouldComponentUpdate(nextProps, nextState) {
}
I know from this answer that having an empty shouldComponentUpdate ...
1
vote
2
answers
420
views
Trace which change of props or state trigger `componentDidUpdate`
I'm making a webpage with react-monaco-editor. I realized that after loading the first page, componentDidUpdate is triggered many times, which does not look normal.
I tried to add logs in ...
0
votes
1
answer
42
views
I need to listen update phase (in life cycle) without constantly sending get requests in react JS
I am trying to write a program that communicates with the client frequently and I need to quickly notice the changes and read the result from the server. But this request is constantly being sent and ...
0
votes
0
answers
205
views
How to keep a React component running in the background for report generation while navigating to other screens?
I am generating a report for multiple datasets by overlaying WMS images from GeoServer as a slideshow and taking screenshots using the html2canvas library.
The problem is that if the user navigates to ...
0
votes
0
answers
973
views
React 18 unexpected behaviour component mount, unmount and then remount [duplicate]
We switched to React 18 from react 17. Strangely all the API code that is running during component mount in useEffect has started executing twice. When we applied console we found that it look like ...
1
vote
2
answers
5k
views
React useMemo x is not a function
I have a react app with hooks where I needed to replicate the behavior of componentWillMount. I read here that for this purpose useMemo could be used so my code roughly looks like this
const Component ...
1
vote
0
answers
41
views
React Native: Why is shouldComponentUpdate being called when neither props nor state have changed?
In my React Native app I have a PureComponent where I log whether props or state have changed each time shouldComponentUpdate() is called, like this:
shouldComponentUpdate(nextProps, nextState) {
...
0
votes
1
answer
54
views
In react world, when does props changing happen? It's definitely triggered by parent component re-rendering?
When it comes to thinking about possibility of props changing, should I only care about parent component updating? Any other possible cases exist for props changing?
I can guess only one case like the ...
0
votes
1
answer
73
views
setState() in componentDidMount() - When is the intermediate state REALLY noticeable TO THE USER?
The React doc states that the intermediate state will not be shown to the user, but why in this example it does show "loading...." (the intermediate state in this case)?
You may call ...
1
vote
1
answer
475
views
componentWillUnmount called before component unmounts
I'm trying to understand when componentWillUnmount is called. I have this class-based component:
class ClassComponent extends React.Component {
constructor(props) {
super(props);
...
0
votes
0
answers
48
views
How to access a dynamically created DOM element in ComponentDidMount lifecycle method in React?
In my react app , I am creating a canvas element dynamically.
Now, I want to access that DOM element from ComponentDidMount lifecycle method, however, I am not able to do that.
Below is my code :
...
0
votes
1
answer
284
views
React life cycle methods (functional components) [closed]
I'm a newbie to react.js and i don't know class components.I'm trying hard to understand the react life cycle.
0
votes
1
answer
2k
views
Functional component with React.memo() still rerenders
I have a button component that has a button inside that has a state passed to it isActive and a click function. When the button is clicked, the isActive flag will change and depending on that, the app ...
2
votes
1
answer
3k
views
What changes if you declare a constant above or inside a React functional component?
My question is what does change if you declare a constant above or inside a React functional component (or a class component also)?
for example what is the difference if I do:
const myName = "...