Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save 3nvi/724372429e45576a4c51cd1df18d5893 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}>{props.content}</div>;
export default connect(state => state.content, { updateTitle: updateTitleAction })(Component)
// With Redux hooks! (you could have also returned an object both as the 1st or the 2nd argument of `useRedux`)
import React from 'react';
import { updateTitleAction } from './actions';
import { useRedux } from 'react-redux';
const Component = props => {
const [content, updateTitle] = useRedux(state => state.content, updateTitleAction);
return <button onClick={updateTitle}>{content}</div>;
}
@techeverri

techeverri commented Apr 25, 2019

Copy link
Copy Markdown

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

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

@3nvi

3nvi commented Apr 25, 2019

Copy link
Copy Markdown
Author

Yup, you are right!

Sorry about that and thanks for pointing that out :)

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