Questions tagged [react-lifecycle]

313 questions
0
votes
1 answer

React: Data rendering on second click, but not on first

I have a modal displaying data that I'm receiving in props. When I open the modal, I should see select data displayed from my props. However, the modal is empty the first time I open it, and populates the second time. If I go on to change the data…
crevulus
  • 1,658
  • 12
  • 42
0
votes
2 answers

Is there a way to make context only re-render if its data changes?

As depicted below, I have a basic react context setup. My desire is child components consuming the context should only re-render when the context data changes, but I'm finding that's not the case. If I update call setData2, which is not associated…
temporary_user_name
  • 35,956
  • 47
  • 141
  • 220
0
votes
1 answer

if any parent class based component receive new props but didnt setstate ...is it will call the componentDidMount()

i am learning react for last 3 month and didn't get 1 things clearly..i wanted to know that if my top level app component get new props but didn't call any set State...is it gonna call the component Did Mount??or it will not call any component Did…
0
votes
1 answer

condition componentWillUnmount() in reactjs

When clicking on button, quote should unmount using componentwillunmount() but I checked by logging to console, unmount not at all running. import React from "react"; import "./App.css"; class App extends React.Component { constructor() { …
Shekar
  • 165
  • 1
  • 5
0
votes
0 answers

Cant access props and state within function in React class Component

I am trying to get values from my state and props in function. This function is fired under componentWillReceiveProps method. However when i try to console log my props and state values under that function i get 'undefined' as result. Is there…
0
votes
3 answers

Implementing loader in React

I've trying to implement a loader which is shown if the component didn't receive data from API yet. Here is my code: import React, {Component} from 'react' import './news-cards-pool.css' import NewsService from '../../services/news-service' import…
Max Pan
  • 137
  • 1
  • 7
0
votes
2 answers

Which ReactJS lifecycle function should be used when an api needs to called more than once due to a prop change?

I have a parent component called DeviceTab.js and a child component called Graph.js. The child component receives two props: name and span. I need to make api calls in Graph.js that are dependent on the initial name or span props and when they get…
bwang
  • 49
  • 7
0
votes
2 answers

How can I synchronise removeEventListener with component state?

sorry about the messy code. Really getting myself in a tangle here. I have a Nav component that I want to hide when the user scrolls. The scroll is detected using the event listener (which is now in useEffect, I don't really know why) which calls…
0
votes
0 answers

ForEach API calls react state not updating correctly

I've got an API to work with where I first need to get a list of ids before calling APIs to get more details of each item. I'm having trouble storing the result of the details in state. Somethings wrong with my understanding of the useState…
Barry Michael Doyle
  • 9,333
  • 30
  • 83
  • 143
0
votes
0 answers

React : Trigger Event even if prevProps & props are same

Here is the scenario Current Code: componentDidUpdate () { if (!isEqual(this.props.data, prevProps.data)) { //logic } } ....... export default connect( state => { return { data: getData(state), }; …
Keval Bhogayata
  • 4,422
  • 3
  • 13
  • 36
0
votes
1 answer

Make POST request and update DB for each and every user in Child Component, using React Life Cycle Method

Here Table shows the previous month user salary details. When click the "Update" button, system will retrieve the necessary data for this month and calculate the new salary and properties and will update the child component table values. Child…
0
votes
1 answer

static getDerivedStateFromError()

I was reading a doc about Error boundaries. In that how did static getDerivedStateFromError() lifecycle update the state of hasError without setState? class ErrorBoundary extends React.Component { constructor(props) { super(props); …
Darshan
  • 56
  • 9
0
votes
1 answer

useCallback with empty dependencies, then what is passed as callback param?

I am not very new to React but below code is hard to understand. const UIContext = React.createContext(); const initialFilter = { ... }; export function UIProvider({ children }) { const [queryParams, setQueryParamsBase] =…
critrange
  • 5,652
  • 2
  • 16
  • 47
0
votes
4 answers

React : Run async function after component unmounted but before another component mounts

hoping someone can help lead me in the right direction with this or point to me to any docs/learnings that might be helpful. I have two React components: When mounted, is hidden (and vice-versa) using…
mcdev
  • 121
  • 2
  • 7
0
votes
1 answer

React - Multiple components did update - why?

Being new to React I'm trying to understand the Lifecycle hooks, is this case ComponentDidUpdate() So I have a location class component - it's a simple form with an input for the user to type a location. My handleSubmit event prevents a new page…
blake
  • 481
  • 4
  • 14