type Property = {
id: string,
name: string,
type: number,
participants: Participant[],
isDirect: boolean,
householdId?: number,
}
this.state.arrResult = [];
for (let i = 0; i < data.results.length; i++) {
this.setState({
arrResult: [...this.state.arrResult, data.results[i].title]
});
}
searchMovie = async () => {
const searchQuery = document.getElementById("movieName").value;
const { results } = await fetch(`https://api.themoviedb.org/3/search/movieapi_key=${API_KEY}&language=ru-RU&query=${searchQuery}&include_adult=true`)
.then(res => res.json());
this.setState({ arrResult: results });
};
export const asyncAction = (...someArgs) => async dispatch => {
const res = await someAsyncCall(...someArgs);
dispatch({ type: SOME_ACTION_TYPE, payload: res });
return res;
};
async dispatch => {
const res = await someAsyncCall(...someArgs);
dispatch({ type: SOME_ACTION_TYPE, payload: res });
return res;
};
return action(dispatch, getState, extraArgument);
можно привести к виду:return (async dispatch => {
const res = await someAsyncCall(...someArgs);
dispatch({ type: SOME_ACTION_TYPE, payload: res });
return res;
})(dispatch, getState, extraArgument);
return action(dispatch, getState, extraArgument);
this.props.myAc("data"));
dispatch(myAc('data'));
dispatch(async dispatch => { ... });
return action(dispatch, getState, extraArgument);
return (async dispatch => { ... })(dispatch, getState, extraArgument);
return action(dispatch, getState, extraArgument);
const test = () => 'test';
const foo = func => func();
console.log(foo(test)); // test
const test = () => 'test';
const bar = func => {
func();
}
console.log(bar(test)); // undefined
const foo = async () => {
await someDelay();
};
// undefined по резолву(окончанию вызова someDelay())
foo().then(result => console.log(result));
const final = (arg) => test => {
test(arg)
}
const foo = final("test");
test => {
test("test");
}
foo(console.log); // вывод в консоль: "foo"
const one = x => y => z => x + y + z ;
const two = one(5);
y => z => 5 + y + z ;
const three = two(10);
z => 5 + 10 + z ;
console.log(three(20)); // 35
dispatch(asyncAction());
async dispatch => {
const res = await someAsyncCall(...someArgs);
dispatch({ type: SOME_ACTION_TYPE, payload: res });
return res;
};
if (typeof action === 'function') {
return action(dispatch, getState, extraArgument);
}
const foo = test => {
test("test");
}
const bar = test => test("test");
const bar = test => {
return test("test");
}
https://reactjs.org/docs/forms.html#controlled-com...
https://reactjs.org/docs/uncontrolled-components.html
да и подумали хотя бы о таком вопросе, как валидация данных на стороне клиента.
Для отправки данных отлично подходит библиотека axios, которая избавляет от необходимости делать многие вещи, вроде вызовов JSON.stringify() и основана на Promise.