Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // saga.js
- function* FetchData() {
- try {
- const AppData = yield call(fetch_Data, "LOAD_APP", App_Url);
- yield put({ type: "LOAD_APP", data: AppData })
- } catch (error) {
- console.log(error)
- }
- }
- function* watchFetchAPI() {
- yield takeEvery("LOAD_ASYNC", FetchData)
- }
- export default function* rootSaga() {
- yield all([
- watchFetchAPI()
- ])
- }
- // action.js
- export function fetch_Data(type, url) {
- fetch(url, {
- method: 'GET',
- headers: {
- "Accept": "application/json",
- "Content-Type": "application/json"
- },
- contentType: 'json'
- }).then(function (res) {
- if (res.ok) {
- return res.json();
- } else {
- console.log("Failed. type: " + type + " Url: " + url);
- }
- }).catch(function (e) {
- console.log("Failed. type: " + type + " Url: " + url);
- console.log(e)
- })
- }
Add Comment
Please, Sign In to add comment