In my redux action, I am making a api call using es6 fetch
api, but I keep getting the error:
Uncaught (in promise) SyntaxError: Unexpected token ‘<‘, “<!DOCTYPE “… is not valid JSON
I dont think its an issue with my server API return type since if I type the API url directly in the browser, I will see the expected response in JSON format.
<code>// package.json
"proxy": "https://www.myapi.com/getdata",
...
</code>
<code>// package.json
"proxy": "https://www.myapi.com/getdata",
...
</code>
// package.json
"proxy": "https://www.myapi.com/getdata",
...
<code>// Redux action file
const getData = async () => {
const reponse = await fetch('/someroute`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const data = await reponse.json();
return data;
}
export const fetchDataAction = () => (dispatch) => {
const reponse = getData();
reponse.then(res => console.log('Response', res))
dispatch({ type: mytype, payload: [] })
}
</code>
<code>// Redux action file
const getData = async () => {
const reponse = await fetch('/someroute`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const data = await reponse.json();
return data;
}
export const fetchDataAction = () => (dispatch) => {
const reponse = getData();
reponse.then(res => console.log('Response', res))
dispatch({ type: mytype, payload: [] })
}
</code>
// Redux action file
const getData = async () => {
const reponse = await fetch('/someroute`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const data = await reponse.json();
return data;
}
export const fetchDataAction = () => (dispatch) => {
const reponse = getData();
reponse.then(res => console.log('Response', res))
dispatch({ type: mytype, payload: [] })
}
<code>// Redux store
import { applyMiddleware, legacy_createStore as createStore } from 'redux'
import { thunk } from 'redux-thunk'
import reducers from './reducers'
const middleware = applyMiddleware(thunk);
const store = createStore(reducers, middleware)
</code>
<code>// Redux store
import { applyMiddleware, legacy_createStore as createStore } from 'redux'
import { thunk } from 'redux-thunk'
import reducers from './reducers'
const middleware = applyMiddleware(thunk);
const store = createStore(reducers, middleware)
</code>
// Redux store
import { applyMiddleware, legacy_createStore as createStore } from 'redux'
import { thunk } from 'redux-thunk'
import reducers from './reducers'
const middleware = applyMiddleware(thunk);
const store = createStore(reducers, middleware)