this.state = address: {
city: '',
},
<InputText
type="text"
value={address.city}
onChange={this.handleChange}
/>
handleChange = (event) => {
console.log(event.target.value)
this.setState((state) => ({ ...state, address: { ...state.address, city: event } }));
}
console.log(event.target.value) выводит [Object object]
console.log('adr', address.city) - synthetic Object
В чем тут может быть дело?
мутируешь state, вместо this.setState
не верно тебе написал. ты в handleChange в city: event написал, вместо city: event.target.value
не понятно в console.log выводит нормально символ console.log(event.target.value) - a а здесь this.setState((state) => ({ ...state, address: { ...state.address, city: event.target.value } })); Uncaught TypeError: Cannot read property 'value' of null Warning: This synthetic event is reused for performance reasons. If you're seeing this, you're accessing the property target on a released/nullified synthetic event. This is set to null. If you must keep the original synthetic event around, use event.persist()
Заскринь код плиз
https://codesandbox.io/s/awesome-silence-rupmu?file=/src/App.js
https://codesandbox.io/s/falling-snowflake-obp9h?file=/src/App.js
Обсуждают сегодня