-1

I am getting this error after using api call. I am trying to fetch data from myjson api. Am i doing something wrong with the current implementation or Is there any better way to call the same api.

import { createAction, handleActions } from 'redux-actions'
import { PLUGIN_NAME, STORE_MOUNT_POINT } from '../constants'
import { Epic,ofType } from 'redux-observable'
import { Store } from '../Store'
import { defer, of } from 'rxjs'
import { mergeMap } from 'rxjs/operators'
import { ajax } from '../util'

const fetchReportTemplate$: Epic<Store.IFSA> = (action$, state$) =>
  action$.ofType(startFetchReportsTemplate.toString(),
      return  ajax(
          {
            url: 'https://api.myjson.com/bins/15dcd9',
            body: ''
          }
        )
      ).map(({ response: { data } }) => {
        return of(clearAllHttpErrors(), receiveReportsTemplateRows(data))
        })
pKay
  • 1,832
  • 4
  • 16
  • 23

1 Answers1

1

Yes, it's syntax error in your code.

action$.ofType(startFetchReportsTemplate.toString(),
      // here, floating return without function
      return  ajax(
m1gu3l
  • 763
  • 1
  • 6
  • 19
  • should i write a function before return? – pKay Jul 02 '19 at 13:10
  • 1
    Yes, but that's not the only problem - you should probably do something like action$.pipe( ofType(type), map(() => ajax(...)), map((response) => doSth(...) ) https://redux-observable.js.org/docs/basics/Epics.html – m1gu3l Jul 02 '19 at 13:37