hi guys I am creating a react native app having some problem when calling api get request its like the response giving some error seems like action not running ill share code below please if anyone know the issue please let me know
NOTE -- when I run the app console in reducer and console in action are not running aslo
error message in console DetailsReducer reducer value in component when i do mapstatetoprops and check the value of reducer its showing like below
Object { details: {}, isFetching: false, error: false }
details: Object { }
<prototype>: Object { … }
error: false
isFetching: false
<prototype>: Object { … }
action file
export function fetchdetails(seesionkey) {
return function (dispatch, getState) {
fetch(`api url`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
seesionkey,
},
body: JSON.stringify({
"appcont": getState().mustdata,
"dataset":{}
}),
})
.then(r => r.json())
.then((rr) => {
console.log('------testinresponse',rr);
if (rr.response.error.errorCode === -4) {
dispatch({
type: 'FETCHFAIL',
payload: ' error again',
});
} else {
dispatch({
type: 'FETCHSUCCESS',
payload: rr,
});
}
})
}
}
reducer
const initialState = {
details: {},
isFetching: false,
error: false
}
export default function DetailsReducer(state = initialState, action) {
switch(action.type) {
case :FETCHSUCCESS
console.log('action goes here', action)
return {
...state,
isFetching: false,
details: action.payload
}
case FETCHFAIL:
return {
...state,
isFetching: false,
error: true
}
default:
return state
}
}
component call
componentDidMount() {
const {seesionkey} = this.props
this.props.dispatch(fetchdetails(seesionkey));
}
mock api
{
"appcont":{
"id":"34435654605",
"name":"no data ",
"details":dummy details",
"code":"demo",
},
"dataset":{
}
}
got the solution data was empty because the api request was get method and passing some data , then changed to post method and all working fine