Skip to content

Instantly share code, notes, and snippets.

@3nvi
Last active April 28, 2019 07:41
Show Gist options
  • Select an option

  • Save 3nvi/a77e907331db7d9f5c7e6bdee15289d6 to your computer and use it in GitHub Desktop.

Select an option

Save 3nvi/a77e907331db7d9f5c7e6bdee15289d6 to your computer and use it in GitHub Desktop.
// Previously
import React from 'react';
import { updateTitleAction } from './actions';
import { connect } from 'react-redux';
const Component = props => <button onClick={props.updateTitle}>Update title</div>;
export default connect(null, { updateTitle: updateTitleAction })(Component)
// With Redux hooks!
import React from 'react';
import { updateTitleAction } from './actions';
import { useActions } from 'react-redux';
const Component = props => {
const updateTitle = useActions(updateTitleAction);
return <button onClick={updateTitle}>Update title</div>;
}
@techeverri

techeverri commented Apr 25, 2019

Copy link
Copy Markdown

Seems the variable in the "With Redux hooks!" should not have props.

-return <button onClick={props.updateTitle}>Update title</div>;
+return <button onClick={updateTitle}>Update title</div>;

@jordancardwell

jordancardwell commented Apr 25, 2019

Copy link
Copy Markdown

First, thanks for the great write up!

Second, should line 20 be:

-const updateTitle = useActions(updateTitleAction);
+const updateTitle = useActions(updateTitle);

@3nvi

3nvi commented Apr 25, 2019

Copy link
Copy Markdown
Author

Yup you both are right guys!

So sorry about that, 1 copy-paste mistake snowballed the whole thing. Thanks for spotting that out and for the kind words.

Have a nice day :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment