Skip to content

Instantly share code, notes, and snippets.

@jasonleehodges
Created October 19, 2019 21:35
Show Gist options
  • Save jasonleehodges/d3614822e90855a116b1706801866ef5 to your computer and use it in GitHub Desktop.
Save jasonleehodges/d3614822e90855a116b1706801866ef5 to your computer and use it in GitHub Desktop.
Simplified component with react-redux hooks
import React, { FunctionComponent } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { RootState } from '~/reducers';
import { selectUser, setUserAction } from 'actions/app';
export const Navigation: FunctionComponent = () => {
const user = useSelector((state: RootState) => selectUser(state));
const dispatch = useDispatch();
const setUser = (user: string) => () => dispatch(setUserAction(user));
return (
<div className={styles.Navigation} onClick={ setUser('me') }>
User name: { user }
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment