developit / preact-redux-example

:repeat: Preact + Redux Example Project
https://preact-redux-example.surge.sh
199 stars 53 forks source link

Using object spread to bind actions #8

Closed robinvdvleuten closed 6 years ago

robinvdvleuten commented 7 years ago

I have removed the bindActions util and just used object spread directly to decrease the filesize even more :)

developit commented 7 years ago

Hmm - doesn't this fail to bind the action creators to dispatch()?

robinvdvleuten commented 7 years ago

Nope I always use it this way in my projects and never had a problem with it. It is even mentioned in the redux documentation;

If an object is passed, each function inside it is assumed to be a Redux action creator. An object with the same function names, but with every action creator wrapped into a dispatch call so they may be invoked directly, will be merged into the component’s props.

mparpaillon commented 7 years ago

Seems to work for me

developit commented 6 years ago

Update: I've been informed actions are bound automatically when an object is passed. No spread needed!