File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -11,10 +11,9 @@ import { useFormatMessage } from 'hooks';
1111const User = ( ) => {
1212 const { id } = useParams ( ) ;
1313
14- const { success, usersList , userData, error } = useSelector (
14+ const { success, userData, error } = useSelector (
1515 ( state ) => ( {
1616 success : state . users . success ,
17- usersList : state . users . list ,
1817 userData : state . users . user ,
1918 error : state . users . error ,
2019 } ) ,
@@ -27,12 +26,7 @@ const User = () => {
2726
2827 useEffect ( ( ) => {
2928 if ( id ) {
30- const userFetched = usersList . find (
31- ( fetchedUser ) => fetchedUser . id === id
32- ) ;
33- if ( userFetched ) {
34- setUser ( userFetched ) ;
35- } else if ( userData . id === id ) {
29+ if ( userData . id === id ) {
3630 setUser ( userData ) ;
3731 } else {
3832 dispatch ( fetchUsers ( id ) ) ;
Original file line number Diff line number Diff line change @@ -41,6 +41,19 @@ export const fetchUsers = (userId = '') => {
4141
4242 dispatch ( USERS_FETCH_DATA_INIT ( ) ) ;
4343 if ( userId ) {
44+ const userFetched = getState ( ) . users . list . find (
45+ ( fetchedUser ) => fetchedUser . id === userId
46+ ) ;
47+
48+ if ( userId ) {
49+ return dispatch (
50+ USERS_FETCH_DATA_SUCCESS ( {
51+ list : getState ( ) . users . list ,
52+ user : userFetched ,
53+ } )
54+ ) ;
55+ }
56+
4457 let userData ;
4558 try {
4659 userData = (
You can’t perform that action at this time.
0 commit comments