Answer the question
In order to leave comments, you need to log in
Is there a nice and simple redux + mongodb example?
From working examples and more or less simple ones, I found only
https://github.com/krambertech/spa-webinar
, but here flux, not react
, tried to figure it out, but everything looks very confusing.
maybe someone recently figured out the react + redux + mongodb interaction and can help?
Answer the question
In order to leave comments, you need to log in
You need react-thunk. In the component, you call action, which sends a request to the server api and passes the received response to the action dispatch.
In the component:
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)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question