Questions tagged [react-lifecycle]

313 questions
0
votes
0 answers

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

React - Unable to set state from the response on initial render

This is the response from redux store : { "newsletter": true, "orderConfirmation": true, "shippingInformation": true, "orderEnquiryConfirmation": true, } This is the jsx file, where am trying to set state. The idea is setting the state from…
0
votes
1 answer

React life cycle methods (functional components)

I'm a newbie to react.js and i don't know class components.I'm trying hard to understand the react life cycle.
sohaib
  • 574
  • 5
  • 16
0
votes
2 answers

ReactJs: Intial Component Rendering doesn't seems to work

I'm working on a project and came across this issue that first time when component is rendered, it doesn't shows anything on the screen. Then componentDidMount is invoked and after that something is visible on the screen. My App Component class App…
Sanchit
  • 1
  • 1
0
votes
1 answer

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 will fetch some data. The button's parent…
kakakakakakakk
  • 467
  • 10
  • 31
0
votes
1 answer

Why is my React component always mounted, unmounted and mounted again?

I'm studying React hooks and I noticed a strange behavior, can someone explain to me why? The component is mounted, sets the state to the initial value and then is unmounted, to be mounted and updated again!!! I understand that every update the…
M.F
  • 45
  • 7
0
votes
1 answer

ReactJS: Class Component Mounting Twice

I am rendering a class component Rates within the functional component of App.js. When the page is loaded, the componentDidMount function is being called twice. Here is App.js: import './App.css'; import Rates from './views/Rates'; function App()…
MattArgo
  • 21
  • 5
0
votes
0 answers

ReactJS Warning: Maximum update depth exceeded when setting a state inside useEffect

I'm trying to create the pagination logic with filtering but When I try to change the state setTotalProducts at useEffect it throws the warning of maximum update depth exceeded at any case totalProducts is in the deps array. const [totalProducts,…
A.Usama
  • 157
  • 2
  • 8
0
votes
1 answer

Rendering the functional component is not the same with class component in ReactJS

I have a class component like this import { Component } from 'react'; import { DEFAULT_HPP, DEFAULT_PAGE, DEFAULT_QUERY, PARAM_HPP, PARAM_PAGE, PARAM_SEARCH, PATH_BASE, PATH_SEARCH, } from '../../constants'; import { Button } from…
0
votes
2 answers

React useEffect to have different behavior on first load and subsequent updates

I am using React with typescript and I want to convert my class component to a functional component, but my class component has two different componentDidMount and comonentDidUpdate behaviors: componentDidMount() { …
adinutzyc21
  • 1,538
  • 1
  • 11
  • 23
0
votes
1 answer

How to prevent unecessary rerenders in child components dependent on memoized parent component state

link to sandbox App has state from which a memoized value is computed which is passed to the Options as props. When the state changes due to a callback passed to Option, App is rerendered, causing a rerender of all of the Options a rerender of…
user6118986
  • 341
  • 2
  • 15
0
votes
1 answer

How to check that a certain prop has received?

I have an synchronization issue. I want to check props is loaded or not to child component. I have wrote a code like that : componentDidMount() { setTimeout(() => { this.setState({ editorContent:…
0
votes
1 answer

React counter not changing on the right interval

I am doing a small project with react lifecycles and I am attempting to change all box colors randomly every time the counter reaches a number divisible by 5 however, the boxes only change when the number is divisible by 10. App.js: import React…
trinity
  • 35
  • 5
0
votes
1 answer

React infinite loop - onClick inside a render calls setState()

Pretty new to React. I'm having some problems rendering a button component. What I'm trying to do is to create a button that, when clicked, fetches some data and displays it under the button itself as a list. To do so, I'm trying to do a conditional…
GD1
  • 77
  • 4
  • 12
0
votes
1 answer

ReactJs: How to execute a function that depends on the result of a setState that's called inside componentDidUpdate

I have this class that loads messages for different conversations: export class Messages extends Component { constructor() { super(); this.state = { page: 0, results_per_page: 10, messages: [], }; …
AG_HIHI
  • 1,705
  • 5
  • 27
  • 69