this.$store.dispatch(GET_ORDER, order).then(() => {
let data = {};
data.id = order;
data.order = {
status,
comment,
totalPrice,
paymentMethod
};
return this.$store.dispatch(PATCH_ORDER, data);
}).catch(() => {
return this.$store.dispatch(POST_ORDER, {
id,
status,
comment,
totalPrice,
paymentMethod
});
}).then(() => {
if (this.responseServer) {
this.$refs.modalSend.hide();
this.status = 1;
}
});
Можно заметить что onChange не возвращает текущий введенный символ в событие.
handleChange(event) {
this.setState({value: event.target.value});
console.log(this.state.value);
}
handleChange(event) {
this.setState({value: event.target.value}, () => console.log(this.state.value));
}
import {ADD_USER} from './actionTypes';
import {HELLO} from './actionTypes';
import firebase from 'react-native-firebase';
export const addUser = (surname, name, patronymic, phone) => {
return async dispatch => {
let db = firebase.firestore();
let user = {
surname: surname,
name: name,
patronymic: patronymic,
phone: phone,
};
let result = 'начальный';
let docRef = db.collection('users').doc(user.phone);
try {
let doc = await docRef.get()
if (doc.exists) {
result = 'Такой номер уже есть';
console.log('Такой номер уже есть');
} else {
db.collection('users').doc(user.phone).set(user);
result = true;
console.log(true);
}
} catch (e) {
result = 'Произошла ошибка';
console.log('Произошла ошибка');
}
return result;
};
};
let result = this.props.onAddUser(
this.state.controls.surname.value,
this.state.controls.name.value,
this.state.controls.patronymic.value,
this.state.controls.phone.value,
).then(result => console.log(result))
handleInputChange(e) {
let inputValue = e.target.value;
clearTimeout(this.timeout);
setTimeout(_ => this.fetchUsers(inputValue), 1000);
}
fetchUsers(value) {
this.setState({isLoaded: false});
axios.get(`url_to_get_users_by_name`, {param: value})
.then((response) => response.json())
.then(
(result) => {
this.setState({
isLoaded: true,
items: result.items
});
},
(error) => {
this.setState({
isLoaded: true,
error
});
}
)
.catch(error => console.log('parsing failed', error))
}