Skip to content

bindActionCreators example is outdated #203

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
gocreating opened this issue Jan 28, 2020 · 0 comments
Open

bindActionCreators example is outdated #203

gocreating opened this issue Jan 28, 2020 · 0 comments

Comments

@gocreating
Copy link

The example of bindActionCreators does not pass generic parameters. Either, optionally pass only one generic parameter: bindActionCreators<ActionCreatorsMapObject<Types.RootAction>>.

Without generic parameters, react component will report not assignable error. The latest redux's bindActionCreators also accepts exact 2 generic parameters. So the example seems outdated.

My current workaround is bindActionCreators<any, any>:

const mapStateToProps = (state: RootState) => ({
  ...
});

const mapDispatchToProps = (dispatch: Dispatch<RootAction>) => bindActionCreators<any, any>({
  ...
}, dispatch);

type Props = ReturnType<typeof mapStateToProps> & ReturnType<typeof mapDispatchToProps>

But the Props is then inferred as type any, which is unacceptable for me.
If I change to bindActionCreators<any, ActionCreatorsMapObject<RootAction>>, then my react component starts to report not assignable error again...

const MyComponent: React.FunctionComponent<Props> = ({ ... }) => {
  ...
};

MyComponent.propTypes = {
  ...
};

export default connect(mapStateToProps, mapDispatchToProps)(MyComponent);

I am really confused about the correct usage of bindActionCreators.
Anyone can help? Thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant