Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // React Component which will call the redux action(this would be in it's own file)
- class MyComponent extends React.Component {
- reactClassMethod() {
- // once your method calls the redux action, you can pass a callback function to wait for the action to complete
- this.props.someReduxAction((data) => {
- // change route based on a condition or remove the if statement to always change route after action completes
- if(data) {
- this.props.history.push('/');
- }
- });
- }
- render() {
- return (
- <div>
- <button onClick={ () => this.reactClassMethod() }>Click Me!</button>
- </div>
- );
- }
- }
- // Redux Action(this would be in it's own file)
- import { SOME_REDUX_ACTION } from './types';
- export default function (callBack) {
- // action logic
- let a = 1 * 2 * 3 * 4;
- // before your return invoke the callback, passing data if you'd like
- callBack(a);
- return {
- type: FETCH_ENVIRONMENTS,
- payload: request
- };
- }
Add Comment
Please, Sign In to add comment