
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
fmp-redux-async-connect
Advanced tools
It allows you to request async data, store them in redux state and connect them to your react component.
How do you usually request data and store it to redux state? You create actions that do async jobs to load data, create reducer to save this data to redux state, then connect data to your component or container.
Usually it's very similar routine tasks.
Also, usually we want data to be preloaded. Especially if you're building universal app, or you just want pages to be solid, don't jump when data was loaded.
This package consist of 2 parts: one part allows you to delay containers rendering until some async actions are happening. Another stores your data to redux state and connect your loaded data to your container.
Using npm:
$ npm install redux-async-connect
import { Router, browserHistory } from 'react-router';
import { ReduxAsyncConnect, asyncConnect, reducer as reduxAsyncConnect } from 'redux-async-connect'
import React from 'react'
import { render } from 'react-dom'
import { createStore, combineReducers } from 'redux';
// 1. Connect your data, similar to react-redux @connect
@asyncConnect({
lunch: (params, helpers) => Promise.resolve({id: 1, name: 'Borsch'})
})
class App extends React.Component {
render() {
// 2. access data as props
const lunch = this.props.lunch
return (
<div>{lunch.name}</div>
)
}
}
// 3. Connect redux async reducer
const store = createStore(combineReducers({reduxAsyncConnect}), window.__data);
// 4. Render `Router` with ReduxAsyncConnect middleware
render((
<Provider store={store} key="provider">
<Router render={(props) => <ReduxAsyncConnect {...props}/>} history={browserHistory}>
<Route path="/" component={App}/>
</Router>
</Provider>
), el)
import { renderToString } from 'react-dom/server'
import { match, RoutingContext } from 'react-router'
import { ReduxAsyncConnect, loadOnServer, reducer as reduxAsyncConnect } from 'redux-async-connect'
import createHistory from 'history/lib/createMemoryHistory';
import {Provider} from 'react-redux';
import { createStore, combineReducers } from 'redux';
app.get('*', (req, res) => {
const history = createHistory();
const store = createStore(combineReducers({reduxAsyncConnect}));
match({ routes, location: req.url }, (err, redirect, renderProps) => {
// 1. load data
loadOnServer(renderProps, store).then(() => {
// 2. use `ReduxAsyncConnect` instead of `RoutingContext` and pass it `renderProps`
const appHTML = renderToString(
<Provider store={store} key="provider">
<ReduxAsyncConnect {...renderProps} />
</Provider>
)
// 3. render the Redux initial data into the server markup
const html = createPage(appHTML, store)
res.send(html)
})
})
})
function createPage(html, store) {
return `
<!doctype html>
<html>
<body>
<div id="app">${html}</div>
<!-- its a Redux initial data -->
<script dangerouslySetInnerHTML={{__html: `window.__data=${serialize(store.getState())};`}} charSet="UTF-8"/>
</body>
</html>
`
}
There are some solutions of problem described above:
Redux Async Connect uses awesome Redux to keep all fetched data in state. This integration gives you agility:
Also it's integrated with React Router to prevent routing transition until data is loaded.
You're welcome to PR, and we appreciate any questions or issues, please open an issue!
FAQs
It allows you to request async data, store them in redux state and connect them to your react component.
The npm package fmp-redux-async-connect receives a total of 0 weekly downloads. As such, fmp-redux-async-connect popularity was classified as not popular.
We found that fmp-redux-async-connect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.