ReactJS - how do I update nested and “normal” state properties?
ReactJS - how do I update nested and “normal” state properties? This is how my state looks like: state constructor(props, context) { super(props, context); this.state = { show: false, btnLabel: 'GO!', car: { owner: false, manufacturer: false, color: false } }; } and this is how I modify state : state handleClickFetchPrice() { this.setState({btnLabel: 'Fetching data...' }); console.log(this.state.fetchPriceBtn); const url = 'some url'; axios.get(url) .then(res => { let car = [...this.state.car]; car.owner = res.data.owner; car.manufacturer = res.data.manufacturer; car.color = res.data.color; this.setState({car}); }) } The attribute car is updated, but fetchPriceBtn is not - the output of console.log(this.state.fetchPriceBtn); is still GO! . car fetchPriceBtn console.log(this.state.fetchPriceBtn); GO! What...
