I do not agree with your approach, but find bellow the solution to your problem:
handleBtnClick() {
actions.MyAction(this.props.history);
}
render() {
return (
<div>
<button onClick={ this.handleBtnClick.bind(this) }>My button</button>
</div>
);
}
When your button is clicked the function handleBtnClick()
is invoked and there you can call your action and pass any props you want.
onClick
expects a function expression (something that evaluates to a function expression). You are not supposed to make complex calls in there such as actions.myAction(this.props.history)
.
I would suggest you to consider using react-router-redux
and handle url transitions using routeActions
and custom redux middleware. I can expand this approach if you are interested.
EDIT:
If you use react-router-redux
then you should take advantage of methods in routeActions
. The method you need in this case is push()
. So, if you want to transition to the /user/account url you just call dispatch(routeActions.push('/user/account'))
and react-router-redux will handle the transition.
Eg:
import { routeActions } from 'react-router-redux';
// Action creator
function mySuperAction(flag) {
return (dispatch, getState) => {
dispatch(routeActions->push('/user/account'));
}
});
You need to have your store properly setup with react-router-redux in order for this to work.
Or from a component:
import { routeActions } from 'react-router-redux';
import { connect } from 'react-redux';
import React from 'react';
class MyComponent extends React.Component {
handleClick() {
this.props.dispatch(routeActions.push('/user/account'));
}
render() {
return (
<div>
<button onClick={ this.handleClick.bind(this) }>My button</button>
</div>
);
}
}
export default connect()(MyComponent);