0

I'm trying to setup Redux ToolKit to see if it will work with an idea that I have. I'm using Redux Toolkit with React Router. I'm trying to update the state within the Route Edi1 and access it from another Route Edi2. I need the Redux store to contain user content from a Text Editor onClick. I'm getting an error at the line const edicontent = useSelector((state) => state.edi.value); within my SendEdi component. The error says value is undefined but it should be set as the initial state which is just "Hello World" for now.

Error:

SendEdi.js:7 Uncaught TypeError: Cannot read properties of undefined (reading 'value')
    at SendEdi.js:7:1

I tried taking that line out to debug and I can see that the payload is being updated from console.log(dispatch(addContent(entryArray)));

So the payload is updating but I can't access it. I combed through my code and I can't find any the issues. I think I might of overlooked something when I setup my slice or configured my store but my setup seems to match up with Redux ToolKit's Quick Start Guide (https://redux-toolkit.js.org/tutorials/quick-start) so the issue is unclear to me. I checked this post and others with the same error but they seem to have gotten the error for different reasons. https://stackoverflow.com/questions/67825922/react-redux-toolkit-typeerror-cannot-read-property-value-of-undefined

Please see the SandBox to review the code. I appreciate the help. Thank you for your time!

Code: https://codesandbox.io/s/edi-forked-fw32n1?file=/src/components/SendEdi.js

2
  • 1
    there's nothing called state.value in rtk, what do you mean by state.value? at line 13 in editSlice.js Commented Oct 3, 2022 at 21:56
  • For that line, I'm trying to update the state with the payload. I used state.value to match up with the setup that they have for the Quick Start Guide. The initial state is set as value: "Hello World" and I thought state.value would overwrite the initial state to update the Redux Store but clearly that isn't right. Commented Oct 3, 2022 at 22:26

1 Answer 1

2

I think the error is here:

const edicontent = useSelector((state) => state.edi)

in store, you do not have edi

export const store = configureStore({
  reducer: {
    counter: ediReducer
  }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.