Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is possible to listen on Redux @@INIT action in middleware

In Redux, there is initial action @@INIT.

Is possible to dispatch another action (in middleware) when this action occurred?

If not, what is best alternative to push action after store is ready?

like image 270
Jurosh Avatar asked Jun 19 '17 08:06

Jurosh


People also ask

What is @@ INIT in Redux?

Handling @@INIT manually will break hot reloading. It is invoked at every hot reload, so if you do your initial data transformation there, it won't work the second time." Therefore, it is actually not intended for the random string to be visible. Follow this answer to receive notifications.

How does middleware work in Redux?

Redux Middleware allows you to intercept every action sent to the reducer so you can make changes to the action or cancel the action. Middleware helps you with logging, error reporting, making asynchronous requests, and a whole lot more.

Which middleware is best in Redux?

Redux thunk is the most popular middleware that allows you to call action creators, which then returns a function instead of an action object.


1 Answers

According to https://github.com/reactjs/redux/issues/186

@@INIT

  • internal action
  • name of that action may differ in dev mode, so if you use it - it might broke app functionality or automatic reloading
  • to sum-up, this action should not be touched in app codebase

How to push initial Redux actions then?

Without library:

const store = createStore(...);
store.dispatch(...)

In middleware like Redux Saga:

function * initialSaga() {
   yield put({ ... })
}
export default function * root() {
   yield fork(initialSaga);
}
like image 193
Jurosh Avatar answered Nov 08 '22 07:11

Jurosh