score:0
here is an example how to use onlylastrequestedpromise:
const makinganapicall = async (url, last = x => x) => {
let response;
try {
response = await last(axios({ url, method: get }));
} catch (e) {
if (e === 'a newer request was made.') {
//ignore this error, current request replaced
// with newer one
return;
}
//something else went wrong, rethrow the error
throw e;
}
if (response.status) {
apiinprogresscheckfn(false, url);
if (
response.status === 200 ||
response.status === 201
) {
dispatch(success(response));
} else {
dispatch(failed(response));
}
}
};
//iife to initialize last only once
const lastsearchapiresult = (() => {
const last = onlylastrequestedpromise('search');
return url => makinganapicall(url, last);
})();
Source: stackoverflow.com
Related Query
- Queue for an api call using react with redux?
- How to implement a dynamic reducer creator for API service call in React with Redux project?
- Using different API url for development and production with React and axios
- Share API data with other components by using React Hook, NO REDUX
- React Redux - Waiting for async api call to finish before next action is dispatched
- SetState with react hook and redux after async call to axios API
- How to wait for action and API call to complete using redux saga?
- Failed with code 405 when using axios to make a call to controller api in asp.net core react application
- React Redux Problem: How to call multiple api in your react component with React Redux Toolkit RTK queries?
- How to call a function from different component using React with Redux Form?
- How to set state at the server for data from API using react redux
- Using React Redux Toolkit with Typescript - set state for reducer
- Conditional API call using Axios with React Hooks
- React + Redux too many re-renders of mapped components with another API call
- Displaying more than one record from different API Call using React Redux
- Fetching data from async api call using react redux
- How to call an API with multiple pages using react
- Call an API method via React Redux on Browser close using 'beforeunload' event listener
- how to write one GET api call using axios instance with and without params in React JS
- React Redux missing in props validation and recommended pattern for initialising container from an external API using redux-observable
- Prevent react component from rendering twice when using redux with componentWillMount
- How to call an API every minute for a Dashboard in REACT
- Using React forwardRef with Redux connect
- Update React Context using a REST Api call in a functional component
- Using react redux with next.js
- React app using API with another origin (CORS)
- No need for state in React components if using Redux and React-Redux?
- componentWillReceiveProps method doesn't run anymore when using redux to call api
- Paginate date-specific results from an API with React and Redux
- Using ES6 Map with React and/or Redux
More Query from same tag
- React: Access Data from Redux in component
- Show/ Hide a div according to toggle Switch on/off
- Translating DropTarget decorator to ES6
- trying to understand: import React, {component} from 'React';
- React-router: Using <Link> as clickable data table row
- setState from an API response using superagent and React
- Remove default animation
- Routing in ReactJS
- How to create temporary States in ReactRedux?
- React.Js: Prevent onClick-events of siblings while a onClick is executed
- When data is added to the firestore, I want to listen with onSnapshot so that the data can be called automatically, but I don't know how to use
- React material table automatic page size
- Error: [div] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>
- export variable from class React
- Bug getting data from server to client using MERN stack
- Not able to display fetched data on page, React JS
- How do I input data with my own in this d3 bubble chart in react?
- Create minified file of CSS using Webpack in React
- Customize Forgot Password Email .Meteorjs
- Reactjs Routing not navigating
- How to test a potential null value from an async void function without using @ts-ignore in TypeScript
- semantic ui: className doesn't work while style does
- Heroku build failure when deploying Node.js/React app
- Material-UI - Can I selectively enable Button ripple?
- componentDidMount() not working in reactJs v15.x
- dispatch action to close modal
- React Uncaught Invariant Violation: Element type is invalid: expected a string
- Render React Component on Button Click Event
- Animate svg rect on button click
- How to submit a form using Enter key in react.js?