I would like to know how I would do to have a return on dispath call something like this, with React:
this.props.store.dispatch(dados, result => {
console.log(result);
});
In this line above console.log
never enter!
index.js : (relevant parts)
const reducers = combineReducers({ pacientes, profissional, procedimento });
const store = createStore(reducers, applyMiddleware(thunkMiddleware));
injectTapEventPlugin();
ReactDOM.render(
(
<MuiThemeProvider theme={theme}>
<Provider store={store}>
..
action:
export function insertPaciente(paciente, pessoa) {
return (dispatch) => {
Axios.callApi('POST', '/pacientes/' + JSON.stringify(paciente) + '/pessoa/' + JSON.stringify(pessoa), {}, pacienteUpdate => {
dispatch(actionCreator.insertPaciente(pacienteUpdate.id, pacienteUpdate));
return pacienteUpdate;
})
};
}
View, where the method that triggers the action: (relevant parts)
pessoa['datacadastro'] = new Date();
pessoa['idempresa'] = empresa.getEmpresa();
paciente['datacadastro'] = new Date();
//Abaixo aqui gostaria de alterar isto ter um callback
this.props.insertPaciente(paciente, pessoa);
const mapStateToProps = state => {
return { pacientes: state.pacientes }
}
const mapDispatchToProps = dispatch => {
return {
insertPaciente: (paciente, pessoa) => {
dispatch(PacienteAction.insertPaciente(paciente, pessoa));
},
updatePaciente: (paciente, pessoa) => {
dispatch(PacienteAction.updatePaciente(paciente, pessoa));
},
}
}
PacienteCadastro.propTypes = {
classes: PropTypes.object.isRequired,
store: PropTypes.object.isRequired
};
const PacientesContainer = connect(mapStateToProps, mapDispatchToProps)(PacienteCadastro);
export default withStyles(styles)(PacientesContainer);
I created actions , reducers , the store using redux-thunk, the return of this. In the backend everything ok, returns the perfect object, but I do not know how to get the result otherwise, for lack of knowledge even in redux. In case I am doing a registration screen, and when I click the RECORD button it executes the action , which effects the dispatch , as said everything is ok until then, but I do not know how to get the result of this!