Anoop K George
Anoop K George

Reputation: 1735

React JS, unable to update Redux state using dispatch hook

My react code contain input field,if I enters text in input field,the redux state updates and displays result in same component but I gets error with my dispatch function. My dispatch function unable to connect with the proper action function.

Please verify my Code

I have copied the code to CodeSandbox

https://codesandbox.io/s/peaceful-currying-hjwur?file=/src/App.js

Upvotes: 0

Views: 143

Answers (2)

Owen Pearson
Owen Pearson

Reputation: 469

You're importing loginUser into rootActions.js and renaming it to loginActions, hence the confusion.

changing line 10 of Header.js to

dispatch(rootActions.loginAction(user_name));

will make it work as expected.

Upvotes: 1

Kamalnrf
Kamalnrf

Reputation: 342

The problem was with this call dispatch(rootAction.loginAction.loginUser(userName)) while rootAction has loginAction but loginAction is a function not an object with loginUser as it is default export.

Change it to dispatch(rootAction.loginAction(user_name)); and it should work.

Upvotes: 1

Related Questions