question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow async redux initial state

See original GitHub issue

right now redux initial state can be set by export const reduxInitialState but I have a request to fulfil where redux initial state can be decided after an Ajax request only. Is there a way to do it? if not I would rather suggest following solution:

export const reduxInitialState = async() => {
   const data = await someAsyncFunction();
   return {
       some: "staticData",
       dynamic: data 
   };
}

And where ever the function is utilised it can be awaited!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
tirthbodawalacommented, Apr 20, 2018

@MikeShobe the release date is targeted for version 2 is end of June.

1reaction
jibaycommented, May 31, 2018

hello,

You can use Redux-Thunk in client.js like this:

import * as appReducers from "./app/reducers";
import thunk from "redux-thunk";


export const reduxInitialState = {
  counter: {
    count: 15
  }
};
export const reduxReducers = appReducers;

export const reduxMiddlewares = [
  thunk,
];

if (module.hot) module.hot.accept();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Async initial state React-Redux Redux-Thunk - Stack Overflow
In my reducer I have a load method: function updateReducer(state, action) { switch (action. type) { case 'load': return action.
Read more >
Redux Fundamentals, Part 6: Async Logic and Data Fetching
It only knows how to synchronously dispatch actions, update the state by calling the root reducer function, and notify the UI that something ......
Read more >
redux-async-initial-state - npm
It is simple redux middleware that helps you load redux initial state asynchronously. Latest version: 0.3.0, last published: 5 years ago.
Read more >
Async actions in bare Redux with Thunk or custom middleware
Learn how to manage asynchronous actions in React apps with Redux ... Let's define the initial state of our application and the reducer...
Read more >
KELiON/redux-async-initial-state - GitHub
With redux it is quite simple to synchronously load initial state, i.e. from localStorage: ... const initialState = JSON.parse ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found