component did update arguments
componentDidUpdate(prevProps, prevState) {
// only update chart if the data has changed
if (prevProps.data !== this.props.data) {
this.chart = c3.load({
data: this.props.data
});
}
}
component did update arguments
componentDidUpdate(prevProps, prevState) {
// only update chart if the data has changed
if (prevProps.data !== this.props.data) {
this.chart = c3.load({
data: this.props.data
});
}
}
componentdidmount
import React, { Component } from 'react';
class App extends Component {
constructor(props){
super(props);
this.state = {
data: 'Jordan Belfort'
}
}
getData(){
setTimeout(() => {
console.log('Our data is fetched');
this.setState({
data: 'Hello WallStreet'
})
}, 1000)
}
componentDidMount(){
this.getData();
}
render() {
return(
<div>
{this.state.data}
</div>
)
}
}
export default App;
USE OF COMPONENTDIDMOUNT()
// good place to call setState here
componentDidMount(){
this.setState({
message: 'i got changed',
});
}
---
// or to make request to the server
componentDidMount() {
fetch('https://api.mydomain.com')
.then(response => response.json())
.then(data => this.setState({ message: data.message }));
}
lifecycles if reactjs
class Clock extends React.Component {
constructor(props) {
super(props);
this.state = {date: new Date()};
}
componentDidMount() { }
componentWillUnmount() { }
render() {
return (
<div>
<h1>Hello, world!</h1>
<h2>It is {this.state.date.toLocaleTimeString()}.</h2>
</div>
);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us