
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
@recruit-tech/redux-async-loader
Advanced tools
Async data loader for Redux apps with React-Router.
redux-async-loader
is incompatible with react-redux@5
For react-redux@5
, you neeed to use the 1.x release of redux-async-loader.
npm install --save redux-async-loader
import { combineReducers, createStore } from 'redux';
import { reduxAsyncLoader } from 'redux-async-loader';
const store = createStore(combineReducers({
reduxAsyncLoader,
...
}), initialState);
import { applyRouterMiddleware, match, RouterContext } from 'react-router';
import { loadOnServer } from 'redux-async-loader';
match({ history, routes }, (error, redirectLocation, renderProps) => {
// ...
loadOnServer(renderProps, store).then(() => {
const content = renderToString(
<Provider store={store} key="provider">
<RouterContext {...renderProps} />
</Provider>
);
});
});
import { render } from 'react-dom';
import { Router, applyRouterMiddleware, browserHistory } from 'react-router';
import { useAsyncLoader } from 'redux-async-loader';
const RenderWithMiddleware = applyRouterMiddleware(
useAsyncLoader(),
);
render(
<Provider store={store} key="provider">
<Router history={browserHistory} render={(props) => <RenderWithMiddleware {...props} />} />
</Provider>
, el);
If you are using react-router-scroll, it should be applied after redux-async-loader.
import useScroll from 'react-router-scroll';
const RenderWithMiddleware = applyRouterMiddleware(
useAsyncLoader(),
useScroll()
);
import { connect } from 'react-redux';
import { asyncLoader } from 'redux-async-loader';
class UserList extends React.Component {
// ...
}
export default asyncLoader((props, store) => store.dispatch(loadUsers(props)))(
connect({ ... }, { ... })(
UserList
)
);
or, with decorator:
@asyncLoader((props, store) => store.dispatch(loadUsers(props)))
@connect({ ... }, { ... })
export default class UserList extends React.Component {
// ...
}
or, with recompose:
import { compose } from 'recompose';
export default compose(
asyncLoader((props, store) => store.dispatch(loadUsers(props))),
connect({ ... }, { ... })
)(class UserList exptends React.Component {
// ...
});
Unlike redux-async-connect, redux-async-loader itself doesn't connect to store. You have to call connect() explicitly if you want to use store's state.
If you want to invoke asyncLoader()
when just querystring (not path) is changed, you must specify key names of querystring to router.
<Route path="items" component=ItemList asyncLoaderProps={{queryKeys: "q, page"}} ... />
Or, you can use the wildcard for any keys of querystring:
<Route path="items" component=ItemList asyncLoaderProps={{queryKeys: "*"}} ... />
import { connect } from 'react-redux';
import { deferLoader } from 'redux-async-loader';
class UserList extends React.Component {
// ...
}
export default deferLoader((props, store) => store.dispatch(loadUsers(props)))(
connect({ ... }, { ... })(
UserList
)
);
or, with decorator:
@deferLoader((props, store) => store.dispatch(loadUsers(props)))
@connect({ ... }, { ... })
export default class UserList extends React.Component {
// ...
}
or, with recompose:
import { compose } from 'recompose';
export default compose(
deferLoader((props, store) => store.dispatch(loadUsers(props))),
connect({ ... }, { ... })
)(class UserList exptends React.Component {
// ...
});
asyncLoader(loader)
Creates Higher-order Component for async data loading by routing.
loader
(Function): Called when this component is routed.
props
(Object): The props passed from React-Router.
See
React-Router API docs
for more info.store
: (Object): Redux's store object.deferLoader(loader)
Creates Higher-order Component for async data loading by mounting and updating.
loader
(Function): Called when this component is mounted or updated.
props
(Object): The props passed from parent component.store
: (Object): Redux's store object.loadOnServer(renderProps, store)
Loads async data on the server side.
renderProps
(Object): The props passed via match()
's callback.
See
React-Router API docs
for more info.store
(Object): Redux's store object.FAQs
Async data loader for Redux apps.
The npm package @recruit-tech/redux-async-loader receives a total of 0 weekly downloads. As such, @recruit-tech/redux-async-loader popularity was classified as not popular.
We found that @recruit-tech/redux-async-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.