Guest User

Untitled

a guest
Dec 13th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. // React Component which will call the redux action(this would be in it's own file)
  2. class MyComponent extends React.Component {
  3.  
  4. reactClassMethod() {
  5. // once your method calls the redux action, you can pass a callback function to wait for the action to complete
  6. this.props.someReduxAction((data) => {
  7. // change route based on a condition or remove the if statement to always change route after action completes
  8. if(data) {
  9. this.props.history.push('/');
  10. }
  11. });
  12. }
  13.  
  14. render() {
  15. return (
  16. <div>
  17. <button onClick={ () => this.reactClassMethod() }>Click Me!</button>
  18. </div>
  19. );
  20. }
  21. }
  22.  
  23. // Redux Action(this would be in it's own file)
  24. import { SOME_REDUX_ACTION } from './types';
  25.  
  26. export default function (callBack) {
  27. // action logic
  28. let a = 1 * 2 * 3 * 4;
  29.  
  30. // before your return invoke the callback, passing data if you'd like
  31. callBack(a);
  32.  
  33. return {
  34. type: FETCH_ENVIRONMENTS,
  35. payload: request
  36. };
  37. }
Add Comment
Please, Sign In to add comment