React
2
Вклад в тег
import { submit } from './actions'
...
onSubmit = (credentials) =>
this.props.submit(credentials)
.then((res) => console.log(res))
.catch((err) => console.log(err))
...
export default connect(null, { submit })(ComponentName);
import api from './api';
export const handleSuccessResponse = (data) => ({
type: USER_LOGGED_IN,
data
})
export const submit = (credentials) =>
(dispatch) => api.request(credentials).then(responseData => dispatch(handleSuccessResponse(responseData)));
import axios from 'axios';
export default request: (credentials) => axios.post('/api/request', { credentials }).then(res => res.data)
case 'LOAD_ALL_DATA':
return {
...state,
cats: action.cats,
dogs: action.dogs,
hozyiny: action.hozyiny
}
export const loadAllData = (response) => {
return {
type: 'LOAD_ALL_DATA',
cats: response.cats,
dogs: response.dogs,
hozyiny: response.hozyiny
}};
state: {
cats: [],
dogs: [],
hozyiny: [],
}