Last active
November 6, 2020 06:11
-
-
Save rkumar1904/86f90952f56a89d7ecc49c1ebd819f01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect } from 'react'; | |
import { connect } from 'umi'; | |
const BasicLayout = (props) => { | |
const { dispatch } = props; | |
useEffect(() => { | |
dispatch({ | |
type: 'user/getCurrentUser', | |
payload: { | |
... | |
... | |
}, | |
}) | |
} | |
}, []); | |
return ( | |
<> | |
<ProLayout> | |
... | |
<ProLayout> | |
</> | |
); | |
}; | |
// to connect the redux store | |
export default connect(({ user }) => ({ | |
user | |
}))(BasicLayout); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { queryUsers } from '@/services/userService'; | |
const UserModel = { | |
namespace: 'user', // identification in redux store | |
state: { | |
currentUser: {}, | |
}, | |
effects: { | |
// generator function | |
*getCurrentUser({ payload }, { call, put }) { | |
const response = yield call(queryUsers); | |
yield put({ | |
type: 'save', | |
payload: response, | |
}); | |
}, | |
}, | |
reducers: { | |
save(state, { payload }) { | |
return { | |
...state, | |
...payload | |
}; | |
}, | |
clear() { | |
return {}; | |
}, | |
}, | |
}; | |
export default UserModel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { apiAccess, apiSecret, url } from '@/utils/env'; | |
import request from 'umi-request'; | |
const headers = { | |
'Content-Type': 'application/json', | |
'api-access': apiAccess, | |
'api-secret': apiSecret, | |
}; | |
export async function queryUsers(params) { | |
return request(`${url}/getCurrentUser`, { | |
headers, | |
method: 'POST', | |
data: params, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment