Questions tagged [react-lifecycle]

313 questions
0
votes
1 answer

Can not implement callback inside of useFocusEffect from React-navigation

I have React-native app with topTabNavigator with three tabs. And usually componentDidMount and componentWillUnmount lifecycle methods don't work when the user changes the tab. Therefore instead of them I decided to use for the side effects…
0
votes
2 answers

Set object values of state using setState method

I have an object as a state variable in React. I want to change its various value using the setState method but it shows. Although I am able to set it using this.state method but this is not the right way I guess. How can I do this? this.state={ …
Pranay kumar
  • 1,983
  • 4
  • 22
  • 51
0
votes
1 answer

Run componentDidMount after a component attribute value change

I don't know whether this is possible in React or not as I am a novice React developer. What I want is to call a function when the attribute (data-link) of my input element changes. I use componentDidUpdate but it triggers whenever any component…
Pranay kumar
  • 1,983
  • 4
  • 22
  • 51
0
votes
1 answer

this.setState is not updating an initialised state property which is an array, despite using componentDidMount

I have looked into other questions such as : this.setState is not updating the state property this.setState not updating state I appreciate that setState is asynchronous. This is my code: import React from 'react'; import ReactDOM from…
JoyFulCode
  • 443
  • 1
  • 6
  • 13
0
votes
0 answers

side effects not in lifecycle methods

I read about react. I have 2 questions. 1) when exactly should I use componentDidUpdate? because sometimes we can do it with any callback function 2)is it good to perform side effects in button clicked. For example, in button click data is sent to…
Ek4m
  • 15
  • 7
0
votes
2 answers

Child Component's props are not getting updated

I have a react component which we are calling conditional based on flag. In ComplianceCards js - I have divided the function based on flag runTriggered. runTriggered ? UpdateCards() : createCards() ParentComponent ComplianceCards - when It goes…
Javascript Coder
  • 5,691
  • 8
  • 52
  • 98
0
votes
1 answer

How to verify login and render conditionally (ReactJS and Firebase)?

I want to make sure that a user is logged in before running rendering either A or B. When I console.log it, I get a true in return when I check if I'm logged in, however wrong if-statement gets rendered. I think that it's because firebase takes its…
Jannemannen
  • 115
  • 1
  • 1
  • 10
0
votes
2 answers

When should React call AJAX request after props change?

I used to call AJAX after props change by ComponentWillReceiveProps() componentWillReceiveProps(nextProps) { if(nextProps.foo !== this.props.foo){ //fetch & call this.setState() asynchronously } } After React 16.3…
0
votes
1 answer

Is it possible to use axios get method inside any method other than componentDidMount?

I am developing Weather App in React js using axios.I am using axios get method inside handleClick method.Is it ok to use like this.and here I deleted app key but I am using that in my project. handleClick=()=> { …
Namita
  • 1
  • 1
0
votes
1 answer

React Native - Rerunning the render method

I have a file here that defines an icon for the title. static navigationOptions = ({ navigation }) => { return { headerRight: () => () } }; HomeHeaderIcon.js export default class HomeHeaderIcon…
user12719912
0
votes
1 answer

React: How to use getDerivedStateFromProps() to set component state. It interferes with controlled component that uses the same state variable

I have a component that receives a variable as a prop. The getDerivedStateFromProps() is typical, meaning that when nextProps.someProp doesn't equal prevState.someStateVar, that prop is assigned to state variable. I also have a Controlled element -…
0
votes
1 answer

Refactoring class component to functional component with hooks, getting Uncaught TypeError: func.apply is not a function

This is my first attempt to refactor code from a class component to a functional component using React hooks. The reason we're refactoring is that the component currently uses the soon-to-be-defunct componentWillReceiveProps lifecylcle method, and…
0
votes
1 answer

why donot componentDidUpdate parameter preState or prevProps gives an reference error?

In react life cycle methods like componentDidUpdate(prevState,prevProps) doesn't gives error. like if its a function it should give error like reference error. What i understand in setState we pass prevState inside a callback function which…
0
votes
2 answers

Call a function one time on page load

I have 3 useEffect functions each calling a updateData function. (Each one is doing something else in addition to that so I can't combine them all.) Because of this, on page load, updateData gets called 3 times. Here's the relevant …
Jessica
  • 9,379
  • 14
  • 65
  • 136
0
votes
1 answer

React Lifecycle- The plot is drawn using the initial state value, and not using the fetched value

I want to fetch the value of the variable 'r2score' from flask. The value is fetched successfully. I even wote a console.log(r2score) statement to see if the fetching works. Here's the problem. Initially it logged a value of 0.1, which is its…