update react app
//NPM
npm install --save react@latest
//Yarn
yarn upgrade react@latest
update react app
//NPM
npm install --save react@latest
//Yarn
yarn upgrade react@latest
how to update react app
//open terminal and run thsi code
cd newreact
//where newreact is the old react app you created
//open package.json in text editor and change the version to latest
//open the same terminal gain and run this
npm install
how to update state in react
// Correct
this.setState(function(state, props) {
return {
counter: state.counter + props.increment
};
});
react lifecycle hooks
class Content extends React.Component {
// ...
componentWillMount() {
this.setState({ activities: data });
}
// ...
}
how to update state react js
class Car extends React.Component {
constructor(props) {
super(props);
this.state = {
brand: "Ford",
model: "Mustang",
color: "red",
year: 1964
};
}
changeColor = () => {
this.setState({color: "blue"});
}
render() {
return (
<div>
<h1>My {this.state.brand}</h1>
<p>
It is a {this.state.color}
{this.state.model}
from {this.state.year}.
</p>
<button
type="button"
onClick={this.changeColor}
>Change color</button>
</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