1

I have create separate slice for entity adapters that I have inside of /redux/slices/messagesSlice.ts. When I try to access store from inside of that file it appears as undefined.

I need to access state (store.getState()) inside of my chatSelector.

On redux website they have all the code reducers and configurestore in one file.

My question is:

Do I need to import store into every component that wants to use selector.selectAll(store.getState()) ??

mnbxx
  • 55
  • 5

1 Answers1

0

A had the same question, and I find this post.

After some time and research, I realize something:

In the documentation in the blue note on the top is written:

For purposes of this reference, we will use Entity to refer to the specific data type that is being managed by a copy of the reducer logic in a specific portion of the Redux state tree, and entity to refer to a single instance of that type. Example: in state.users, Entity would refer to the User type, and state.users.entities[123] would be a single entity.

So for me below worked fine.

import { useSelector } from 'react-redux';

 const jobName = useSelector((state: RootState) => state.job.entities[props.id]?.jobName);
Izabela Furdzik
  • 511
  • 6
  • 8