TypeError: undefined is not an object (evaluating '_get2.queue')
Opened this issue · 9 comments
Hello,
I have setup as per your example project https://github.com/RobPando/offlineTweet.
I am getting proper isConnected NetInfo callbacks. The problem is i get the error:
This happens when
yield put({type: ONLINE});
I am using 0.61.5
Hey @bijuC1983 thanks for bringing this into attention. I use this in multiple projects and have not run into this issue. Could you provide more info so I can take a look at it please. Are you using redux sagas? what are you naming the offline reducer store? this offline: require('redux-offline-queue').reducer,
? and how are you declaring the offline actions? could you provide a snippet if possible.
Hello @RobPando. Thank you for your response. Yes, I am using redux-saga.
export default () => { const rootReducer = combineReducers({ //User user: persistReducer(userPersistConfig, UserReducer), //Patient patient: persistReducer(patientPersistConfig, PatientReducer), // Doctor doctor: persistReducer(doctorPersistConfig, DoctorReducer), master: MasterReducer, article: ArticleReducer, story: StoryReducer, comment: CommentReducer, call : CallReducer, appointment: AppointmentReducer, notification: NotificationReducer, transaction: TransactionReducer, offline: require('redux-offline-queue').reducer, });
Also, I was able to get this working by manually changing inside node_modules.
I changed,
var _get2 = (0, _lodash.get)(getState(), stateName),
to
var _get2 = (0, _lodash.get)(getState().toObject(), stateName),
@bijuC1983 this is great, really appreciate it. The curious thing is that getState
should return an object. could you place a console log in there to see what getState()
logs out please.
It does return an object in console. But, when I try to get any property('offline') from that object it returns undefined. It only works after toObject(). Please note I am on 0.61.5.
I also think #17 is related. And also this one
https://stackoverflow.com/questions/61956066/react-native-undefined-is-not-an-object-evaluating-get2-queue
Interesting, I will look into this. Thanks again!
Hello @RobPando I was wondering if you were able to have a look into it.
Also, I wanted to ask that is there a way I can manually add an action to the queue? What I would like to achieve is that if the network disconnects in the middle of a network operation (It was online when the action was fired), I would like to add the action to the queue when the network request times out.
I am using redux-saga and apisauce.
Any pointer will be really helpful.
@bijuC1983 I have not had a chance yet but I will this week. As for your question, I believe what you are trying to do is re-queue an action. There is a way to manually queue the action again, I use this for every offline request this is also good if the server is down for any reason and for your case also if it times out you can re-queue it. So if you are using redux-saga you can do something like this:
import { put, call } from "redux-saga/effects";
import { queueAction } from "redux-offline-queue";
function* postBlog(action) {
cont { someParam } = action;
const response = yield call(myAPI, someParam);
if (response.ok) {
// success
else if (response.status === 500) {
// server error
// this manually adds the action back into the queue
yield put(queueAction(action))
} else {
// client error do something else
}
}
let me know if this helps