I'm making a react flux app where the user first create a user and that user will be saved in a database.
so first I create a action named CREATE_USER looks like this
export function createUser(name, username, password) {
dispatcher.dispatch({
type: "CREATE_USER",
name,
username,
password,
});
}
then i register that action in my Store like this
handleActions(action) {
switch(action.type) {
case "CREATE_USER": {
this.createUser(action.name, action.username, action.password);
break;
}
}
}
this will trigger a create user function that will make a http post to the backend and save that user in the database
createUser(name, username, password) {
axios.post('/api/user', {
name: name,
username: username,
password: password
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error.response);
});
}
then in my component i call createUser on handlesubmit function
_handleUserSubmit(event) {
event.preventDefault();
let name = this.name.value;
let username = this.username.value;
let password = this.password.value;
UserActions.createUser(name, username, password);
}
But how do i return the response object or error object from the createuser function to the component?