Skip to content

Instantly share code, notes, and snippets.

@koss-lebedev
Last active June 24, 2019 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koss-lebedev/035c5e534175d11d10618482ff78124b to your computer and use it in GitHub Desktop.
Save koss-lebedev/035c5e534175d11d10618482ff78124b to your computer and use it in GitHub Desktop.
import React, { useEffect, FC } from 'react'
import { useSelector, useDispatch } from 'react-redux'
import UserList from '../../components/UserList'
import { RootState, RootDispatch } from '../../store'
const useRematchDispatch = <D extends {}, MD>(selector: (dispatch: D) => MD) => {
const dispatch = useDispatch<D>()
return selector(dispatch)
}
const Users: FC = () => {
const users = useSelector((state: RootState) => state.users)
const { load } = useRematchDispatch((dispatch: RootDispatch) => ({
load: dispatch.users.load
}))
useEffect(() => {
load()
}, [])
return <UserList users={users} />
}
export default Users
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment