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?
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.
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.
Redux thunk is the most popular middleware that allows you to call action creators, which then returns a function instead of an action object.
According to https://github.com/reactjs/redux/issues/186
@@INIT
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With