score:2
Accepted answer
before you fire the api call, set the loading state to true. when your api call completes or fails, set the loading state to false.
const [loading, setloading] = usestate(false);
const apicall = () => {
// before you fire the api call, set the loading state to true.
setloading(true);
axios.get('api/endpoint')
.then(res => {
setcontext(prev => ({...prev, state: res.data})))
// when your api call completes or fails, set the loading state to false.
setloading(false);
})
.catch(e => {
console.log(e);
// also need to set loading to false if your request fails
setloading(false);
});
}
then use the loading
state variable to control your components (eg. show a spinner).
<button loading={loading} ... />
Source: stackoverflow.com
Related Query
- Ant Design download loading spinner during api call
- How to change default Loading Spinner for Ant Design Pro
- How to set a loading boolean on component during Redux api call
- In ant design protable, is there a way to use a select in a search field, where all the options for the select are from an API call to remote server?
- React Ant Design styles not loading
- How do I tell the custom onSuccess function to stop the upload spinner in Ant Design Upload component?
- ant design - Modal value reset on "cancel" and "X" close button - API RESPONSE BASE REACT JS
- How to return state in reducer function during API call
- React not loading state properly on mount during axios call
- Ant Design react - change default spinner for all components
- Ant Design table continues to show loading even when the table is populated by data
- how to better format data pulled from api onto a ant design table
- How to place the data API into the Ant Design Cascader?
- Ant Design components style not loading correctly
- In Reactjs how to insert api data into ant design table
- Ant Design TreeSelect map data from API to title value keys
- React Flux Loading Initial Data via API Call
- Loading styles in ant design ui for react components
- How to call useNavigate inside useEffect? - For bottom navigation in Ant Design - Mobile
- Download CSV file from browser after making axios call from React to Nodejs Api
- React loading screen before fetching API call
- How to show a loading indicator during sending API request
- React display loading animation for api call duration
- API call will not work only first time loading in React
- How to display a spinner when data is loading from server by fetch api in REACT JS?
- Can't update state to change display on page during api call
- Loading react table through API call
- How to call onFinish method of form in child component from parent in ant design framework
- how to set Loading while api call in reactjs?
- React: How to get loading spinner to show whilst API data loads into my chart.js chart
More Query from same tag
- Animation duration issue
- TypeError: Cannot read property 'cases' of undefined
- Filter list of Objects according to the month?
- React setState won't update, if I add an if statement
- Pass a state value from redux reducer to another reducer
- Eslint React Hooks Error: eslint-plugin-react-hooks exhaustive deps warning for a function dependency in useEffect
- In React Router Dom, redirect not work if i don't press enter or refresh page
- How to make Material UI Temporary Drawer button as icon instead of text?
- SCSS modules not loading in NextJS
- rxjs - delay function return until a stream value meets a condition and is unsubscribed
- Nginx reverse proxy multiple react apps
- 'npm start' gives an error and does not start the development server
- How to know if an array is Empty?
- React: Render parent component only if children will render
- I want to display different contents when there is no item in map or filter
- Search Table in ReactJs
- how to set onClick event on a button inside a datatable in ReactJS
- reaching data inside an object while using map
- map() as a callback in setState() in React running the conditional twice oddly
- onError in img tag in React
- React Boostrap Overlay
- How to apply styling for 3rd party css framework like bootstrap
- Can't mock axios instance in Typescript
- React-intl, Redux-Form combine and raise warnings
- React Router 4 Failed context type
- Disjoint unions in React.Component props
- React Test case for the button disabled or not on the basis of state value
- react radio doesn't work
- Filtering Down Component Map using click function react
- how to override TextField of floating label text and underline color in material-ui-next?