Questions tagged [react-lifecycle]
313 questions
0
votes
0 answers
the disappearance of states when reloading the page
I am making a clothing store, I made the product presentation page. it works fine, but when i reload the page, state reverts to the initial state and returned to the console "y a rien pour le remplir". as the componentDidMount did not work.
---the…

sifo
- 33
- 5
0
votes
1 answer
Video-React: handleStateChange gets called multiple times when it should be called only once
I am using Video-React to implement video playing functionality in my project:
{
this.state.player = player;
}}
src={videoURL}
>
I am tracking state…

AG_HIHI
- 1,705
- 5
- 27
- 69
0
votes
2 answers
I want the combined functioanlity of ComponentDidMount and ComponentDidUpdate in React js
I am fetching API data using axios and that API has query parameter (e.g.: searchQuery, which is defined in state). I have declared it's initial value in state and axios call in componentDidUpdate.
Now I want my user to input the data in the form…

Umar Javed
- 55
- 8
0
votes
2 answers
ReactJs: How to execute code before a component mounts since componentWillMount is deprecated?
I am trying to redirect user to home page conditionally before component mounts:
componentWillMount(){
console.log("componentWillMount is called.")
let userHasNotChosenOpportunity = true
if (userHasNotChosenOpportunity) {
…

AG_HIHI
- 1,705
- 5
- 27
- 69
0
votes
0 answers
react useEffect hook causes infinite loop
The usePaginator is intended to fetch data (and set hasNextPage if there is more data to fetch), once page, userData or category change, but it causes infinite loop allegedly due to setInfo which appears in method which then is called in useEffect…

IlyaNesterow17
- 33
- 3
0
votes
2 answers
React substitute for componentDidReceiveProps
I am creating a chat app and I have a component called ChatBox. ChatBox subscribes to a WebSocket when the user clicks on a chat channel. Right now, this is done in the constructor. The issue is that I now need to let the user change channels, but…

Will Kanga
- 652
- 1
- 6
- 12
0
votes
0 answers
componentDidUpdate(prevProps) is not being called
**I'll post the code first and then explain what's the issue I'm getting later.
class ParentComponent extends Component {
constructor() {
super()
this.state = {
id: null,
}
}
render() {
const dataTarged = "#col" + id
…

kivul
- 1,148
- 13
- 28
0
votes
2 answers
When exactly is state available in React?
I was interviewed for a front end developer position the other day and was asked this question verbatim. He noted it was a "gotcha" question. I was not sure what the actual answer is. Would it be something like componentDidMount from a lifecycle…
0
votes
0 answers
What difference does it make if we don't perform the same side-effects after every re-render in React class component?
I came across this class component with 2 lifecycle methods handling the component's side-effects after each re-render:
componentDidMount and componentDidUpdate
I copied the example (at the bottom) and tried to play with it by deleting…

Eddie Lam
- 579
- 1
- 5
- 22
0
votes
1 answer
Why won't my changes to state show in my componentDidMount lifecycle?
I am building an app using React and for my homepage, I set state in the componentDidMount lifecycle:
export default class HomePage extends Component {
state = {
posts: [],
token: '',
};
//Display posts when homepage renders
…

Casey Cling
- 401
- 2
- 5
- 15
0
votes
2 answers
Migrating React JS Lifecycle method to Hooks
I'm trying to convert componentDidUpdate to useEffects. The examples I've seen were pretty straight forward but since the componentDidUpdate didn't seem too involved. I need make conditional changes but not sure what I really need to do to…

JavaScriptGirl
- 1
- 3
0
votes
3 answers
Need to add ComponentDidMount to stateless function
I need to add this, but componentDidMount() isn't recognized because my component below is stateless and I'm not sure how I would extend it or whatever best practice would be here?
Below is my component -
export default ({ children, meta, title })…

Tom Hanks
- 594
- 1
- 5
- 21
0
votes
1 answer
React component did mount but stated unmounted actually
I had a weird problem with componentDidMount and componentWillUnmount behavior. When the component unmount, and then remount again because of the effect of a HOC which come from a library called react-stockchart
Something like this:…

Minh Kha
- 1,052
- 8
- 13
0
votes
1 answer
React native correct way to cancel promis inside component did mount and optimise component
I'm trying to handle a promise inside a componentDidMount, i want to prevent infinite call to the promise so i want to implement an isMounted variable but i don't really understand when to set the isMounted to false to cancel the promise call.
My…

Khaled Boussoffara
- 1,567
- 2
- 25
- 53
0
votes
1 answer
Maintaining a dictionary of React refs while avoiding re-renders
I've been boxed into a rather uncomfortable situation in React where a parent element has to manage the refs of many children in a large (read: expensive-to-render) component tree that changes over time. The children whose refs I need also changes,…

concat
- 3,107
- 16
- 30