Registry / backend / react-api-data

react-api-data

JSON →
library1.2.0jsnpmunverified

Automate calling external APIs and handling response data with React and Redux. Supports any API with JSON responses. Uses Fetch for performing API requests, normalizr for handling response data, and Redux for storing data. Current stable version 1.2.0. Release cadence is irregular, with last release in 2020. Key differentiators: built-in normalizr integration for entity normalization, support for invalidating cached requests, and optional React Suspense support. Alternative to Apollo Client or react-query, but specific to Redux ecosystems.

npm install react-api-data
INSTALL
IMPORT
SIG · REACT-API-DATA
R
react-api-data
backendjavascriptv1.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useApiData
import { useApiData } from 'react-api-data'
import useApiData from 'react-api-data'
named export, not default. Use this hook in React components.
configure
import { configure } from 'react-api-data'
import { configure } from 'react-api-data/hooks'
import from 'react-api-data', not a subpath.
reducer
import { reducer } from 'react-api-data'
const reducer = require('react-api-data').reducer
ESM import works, CommonJS require also works for Node.js/Webpack bundling.
withApiData
import { withApiData } from 'react-api-data'
Higher-order component alternative to useApiData. Use with class components.
invalidateRequest
import { invalidateRequest } from 'react-api-data'
Action creator to invalidate cached API requests. Use with dispatch.

Configures store with react-api-data reducer, defines endpoints with normalizr schema, and uses useApiData hook to fetch and display article data.

import { schema } from 'normalizr'; import { createStore, applyMiddleware, combineReducers } from 'redux'; import { configure, reducer, useApiData, invalidateRequest } from 'react-api-data'; import thunk from 'redux-thunk'; import React from 'react'; import { Provider, useDispatch } from 'react-redux'; const authorSchema = new schema.Entity('Author'); const articleSchema = new schema.Entity('Article', { author: authorSchema }); const endpointConfig = { getArticle: { url: 'http://www.mocky.io/v2/5a0c203e320000772de9664c?:articleId/:userId', method: 'GET', responseSchema: articleSchema }, saveArticle: { url: 'http://www.mocky.io/v2/5a0c203e320000772de9664c?:articleId', method: 'POST', afterSuccess: ({ dispatch, request, getState }) => { dispatch(invalidateRequest('getArticle', { articleId: request.params.articleId, userId: getState().userId })); } } }; const store = createStore(combineReducers({ apiData: reducer }), applyMiddleware(thunk)); store.dispatch(configure({}, endpointConfig)); const Article = ({ articleId }) => { const article = useApiData('getArticle', { articleId, userId: 1 }); return ( <div> {article.request.networkStatus === 'success' && ( <> <h1>{article.data.title}</h1> <p>{article.data.body}</p> </> )} </div> ); }; const App = () => ( <Provider store={store}> <Article articleId='123' /> </Provider> ); export default App;
Debug
Known issues
gotchaMissing peer dependencies react-redux, redux-thunk, normalizr will cause runtime errors.
fix
Install peer dependencies: npm install react-redux redux-thunk normalizr
affects: >=1.0.0
gotchaGlobal fetch must be available. In older browsers or Node.js, you need a polyfill.
fix
Install and import a fetch polyfill like 'whatwg-fetch' before using react-api-data.
affects: >=1.0.0
breakingThe library may not be compatible with React 18's concurrent features beyond Suspense.
fix
Use React Suspense as documented, but avoid other concurrent patterns like useTransition with outdated versions.
affects: >=1.0.0
deprecatedThe afterSuccess callback signature in endpoint config may change in future major versions.
fix
Stay updated with changelog when upgrading to v2.
affects: 1.x
Errors
Common errors & fixes
Could not find module 'react-api-data'
Package not installed or missing peer dependencies causing resolution failure.
fix
Run `npm install react-api-data react-redux redux-thunk normalizr`
Uncaught TypeError: (0 , _reactApiData.useApiData) is not a function
Importing default instead of named export, or using incompatible version.
fix
Use `import { useApiData } from 'react-api-data'` (curly braces).
TypeError: Cannot read property 'networkStatus' of undefined
useApiData returned undefined because endpoint key is wrong or params missing.
fix
Ensure endpoint name matches config and params object is passed correctly.
Uncaught Error: Could not find 'store' in the context of 'Connect(Article)'. Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(Article) in connect options.
Component using withApiData is not wrapped in <Provider store={store}>.
fix
Wrap the component tree with <Provider store={store}> from react-redux.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
react-reduxrequiredpeer dependency required for Redux integration
redux-thunkrequiredpeer dependency required for async actions
normalizrrequiredpeer dependency required for response schema normalization
Agent activity
36 hits · last 30 days
node
30
Amazon
1
OpenAI (training)
1
Resources
react-api-data — npm install react-api-data · libregistry