bookworm-react icon indicating copy to clipboard operation
bookworm-react copied to clipboard

when I try to save a book I get this error => TypeError: Cannot read property 'catch' of undefined

Open ghost opened this issue 7 years ago • 12 comments

Hello, when I try to save a book i get this error,

TypeError: Cannot read property 'catch' of undefined
BookForm._this.onSubmit
C:/code/bookworm/src/components/forms/BookForm.js:55
  52 | this.setState({ errors });
  53 | if (Object.keys(errors).length === 0) {
  54 |   this.setState({ loading: true });
 55 |   this.props
  56 |     .submit(this.state.data)
  57 |     .catch(err =>
  58 |       this.setState({ errors: err.response.data.errors, loading: false })

I run mongo db in cmd windows like this : C:\Program Files\MongoDB\Server\3.4\bin\mongod --dbpath C:\code\bookworm-api --port 27017

ghost avatar Oct 05 '17 00:10 ghost

I have the same error,Have you solved it?

xkux8023 avatar Feb 09 '18 03:02 xkux8023

Hi @Remchi, just to follow on from what these two are saying. I am really struggling to solve the issue.

When I log in or sign up I keep on having an issue with the .catch in the onSubmit function. I initially was getting this error, like the others above: image

But when I console.logged the err I get to the real issue which is I am not catching my API error, but a redux error:

Error: Given action "USER_LOGGED_IN", reducer "user" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.
    at combination (combineReducers.js:123)
    at computeNextEntry (<anonymous>:2:27469)
    at recomputeStates (<anonymous>:2:27769)
    at <anonymous>:2:31382
    at Object.dispatch (createStore.js:165)
    at dispatch (<anonymous>:2:31875)
    at index.js:14
    at dispatch (applyMiddleware.js:35)
    at users.js:5
    at <anonymous>

What looks to me is that redux doesn't like an action being "cancelled" and wants us to explicitly handle it return the previous state. So my .catch is picking up an error from redux, before it is catching the error I am waiting for from the api.

Any idea how I would solve this issue? I can't find any meaningful differences between our code that would stop this from happening.

nickmask avatar Feb 21 '18 11:02 nickmask

@nickmask same problem here

JuarezLopesJr avatar Mar 02 '18 13:03 JuarezLopesJr

Even if i rewrote the api to work with mysql, i have the same problem. I found no work around or solution yet. I can't find if it's a redux or a react problem.

OK solved.

bartbdx avatar Mar 08 '18 19:03 bartbdx

Hi @nickmask. I didn't find what was the bug, but i rewrote using redux-saga instead of thunk. Thought you might wanna look. Cheers! https://github.com/JuarezLopesJr/saga_book

JuarezLopesJr avatar Mar 14 '18 21:03 JuarezLopesJr

Thanks @JuarezLopesJr . I am more use to sagas anyway, so I think I'll make the switch as well. Cheers!

nickmask avatar Mar 15 '18 00:03 nickmask

I had this same issue, but I was able to fix it by adding a 'return' to the LoginPage submit function

div-cowboy avatar Apr 22 '18 16:04 div-cowboy

may be your forgot to export USER_LOGGED_IN on types.js file, so that is make type on user Logged In(user) has value undefined.

sgtkuncoro avatar May 19 '18 00:05 sgtkuncoro

Hi @iamkratos, I am also facing same issue. Can you please send me the exact location where to add return statement...if possible the please share the code.

yoursravin avatar Aug 28 '18 12:08 yoursravin

Hi @Remchi, just to follow on from what these two are saying. I am really struggling to solve the issue.

When I log in or sign up I keep on having an issue with the .catch in the onSubmit function. I initially was getting this error, like the others above: image

But when I console.logged the err I get to the real issue which is I am not catching my API error, but a redux error:

Error: Given action "USER_LOGGED_IN", reducer "user" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.
    at combination (combineReducers.js:123)
    at computeNextEntry (<anonymous>:2:27469)
    at recomputeStates (<anonymous>:2:27769)
    at <anonymous>:2:31382
    at Object.dispatch (createStore.js:165)
    at dispatch (<anonymous>:2:31875)
    at index.js:14
    at dispatch (applyMiddleware.js:35)
    at users.js:5
    at <anonymous>

What looks to me is that redux doesn't like an action being "cancelled" and wants us to explicitly handle it return the previous state. So my .catch is picking up an error from redux, before it is catching the error I am waiting for from the api.

Any idea how I would solve this issue? I can't find any meaningful differences between our code that would stop this from happening.

You might forget to send the status code from the server. Do check it.

SakaSaiTrinath avatar Sep 30 '18 11:09 SakaSaiTrinath

Hi @Remchi, just to follow on from what these two are saying. I am really struggling to solve the issue.

When I log in or sign up I keep on having an issue with the .catch in the onSubmit function. I initially was getting this error, like the others above: image

But when I console.logged the err I get to the real issue which is I am not catching my API error, but a redux error:

Error: Given action "USER_LOGGED_IN", reducer "user" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.
    at combination (combineReducers.js:123)
    at computeNextEntry (<anonymous>:2:27469)
    at recomputeStates (<anonymous>:2:27769)
    at <anonymous>:2:31382
    at Object.dispatch (createStore.js:165)
    at dispatch (<anonymous>:2:31875)
    at index.js:14
    at dispatch (applyMiddleware.js:35)
    at users.js:5
    at <anonymous>

What looks to me is that redux doesn't like an action being "cancelled" and wants us to explicitly handle it return the previous state. So my .catch is picking up an error from redux, before it is catching the error I am waiting for from the api.

Any idea how I would solve this issue? I can't find any meaningful differences between our code that would stop this from happening.

Do compare your code with this -> https://github.com/shah77/User-authentication.

shah77 avatar Oct 08 '18 04:10 shah77

image From the actual video, played around with the curly braces and fixed it, hope it helps.

ncsereoka avatar Feb 08 '20 19:02 ncsereoka