0

Get API file

import { apiUrl } from '../config'
const baseUri = apiUrl
const uri = {
outline : '/course/income/outline'
 }
const getURI = (key) => baseUri + uri[key]

module.exports = { apiMiddleware, get, post, put, ...{ delete: del }, uri, getURI }

Try pass this to my axios URL

import Api from '../middleware/api'
    export function IncomeList () {

        return dispatch => {

            return (

                axios.post(Api.getURI(outline),{}, {
          headers: { 'X-Authenticated-Userid': '15000500000@1' }
         }).then(function (response) {


                    console.log(response.data);
                    dispatch(receiveData(response.data.body));

                })
            .catch((error) => {
                    console.log(error);
                })
                )
        }
    }

But I get error Uncaught ReferenceError: outline is not defined. How to Pass correct URL ?

0

1 Answer 1

1

Pass string literal to getURI method:

Api.getURI('outline')

Calling Api.getURI(outline) makes interpreter look for outline variable, which is undefined in the current scope (hence ReferenceError).

Protip: linter, like ESLint, would catch this error early.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.