lord_drgical
lord_drgical

Reputation: 153

having trouble fixing dependency cycle in redux

One of my redux actions requires access to a class that manages api requests. However in my api requests class, I wrote a method that requires importing the data store. I then began getting the following error:

Cannot access 'WEBPACK_DEFAULT_EXPORT' before initialization

I looked up the error and mentions It is due to a dep cycle, it seems that this pattern is causing the importing of an uninitialized data store. summery: Since my redux slice imports the api class and the api class depends on the redux store how can i restructure my code to fix this pattern?

Upvotes: 0

Views: 276

Answers (1)

markerikson
markerikson

Reputation: 67489

We specifically advise Redux users that you should never import the store directly into other files, except the main app entry point file, because of this sort of import cycle problem.

The best approach here would be to restructure your logic so that this class file doesn't need to use the store at all.

As a secondary fallback, you can expose a setter from that module that saves the store reference, and call that setter from the entry point on startup.

Upvotes: 2

Related Questions