
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
universal-data-loader
Advanced tools
universal-data-loader is a library that aims to make data fetching easier to manage in React application. You can easily manage cache, integrate with data persisters(such as localStorage), configure fetching behaviours. It works with redux + redux-saga or the new React Context API
$ npm i universal-data-loader --save
// an api call is simply a function that returns promise
type ApiCall = (args: any) => Promise<any>;
Let's create a mock api call which returns a random number in 1000ms
const mockApi = () => {
return new Promise((resolve) => {
setTimeout(() => resolve(Math.random()), 1000)
})
}
import { DataLoader } from 'universal-data-loader'
// if you are using redux and redux-saga, import this one:
import { ReduxDataLoader as DataLoader } from 'universal-data-loader'
export const App = () =>
<DataLoader name="randomNumber" apiCall={mockApi}>
{
(loader) => {
if (loader.loading) {
return <div>loading...</div>
}
if (loader.error) {
return <div>Error!!!</div>
}
return <div>{loader.data ? loader.data : 'No Data!'}</div>
}
}
</DataLoader>
The loader that child function gets as parameter:
// data: the data you get from the api call
// loading: the load status, `true` when api call is running
// error: the Error throw from api call
// lastUpdateTime: the last time that data was loaded from api call
// lastErrorTime: the last time that data fetching throw an error
// load: call this function to manually start to load data
interface Loader<T = any> {
data: T | null
loading: boolean
error: Error | null
lastUpdateTime?: number
lastErrorTime?: number
load: () => void;
}
import { DataProvider } from 'universal-data-loader'
ReactDOM.render(
<DataProvider>
<App />
</DataProvider>,
document.getElementById('root')
)
import {
dataLoaderSagas,
dataLoaderReducer,
DATA_LOADER_NAMESPACE,
} from 'universal-data-loader'
// combine dataLoaderReducer with your own reducers and give it the name: DATA_LOADER_NAMESPACE
const reducers = combineReducers({
[DATA_LOADER_NAMESPACE]: dataLoaderReducer,
})
// run sagas with dataLoaderSagas
sagaMiddleware.run(dataLoaderSagas)
FAQs
Makes it easy to load data for your components
The npm package universal-data-loader receives a total of 2 weekly downloads. As such, universal-data-loader popularity was classified as not popular.
We found that universal-data-loader 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
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.