score:3
put a []
after the function in useeffect
like this:
useeffect(() => {
covidapi.getdata({url:'/totals'})
.then((response) => {
settotal(response.data[0]);
setmessage('');
console.log(response.data);
})
.catch((error) => {
setmessage("no data found");
console.log(error);
})
}, []);
this will call the api only once.
Source: stackoverflow.com
Related Query
- React useEffect calls API too many time, How can I limit the API call to only once when my component renders?
- How can I use useEffect in React to run some code only when the component first mounts, and some other code whenever an event occurs (repeatedly)?
- How can I filter json data from api call in react into different sections of the component
- How can I route to a page only when a post action in the actions page is successful while doing an api post call
- useEffect causing it to call the method to get posts way too many times. I only want to get the posts when my query changes
- React TypeScript: How to call an api and set state each time the route changes
- How can I solve ? Too many re-renders , React limits the number of renders
- How can I ensure that a React component is loaded only after some API call has been made?
- How to Make A second API call based on the value gotten from the first. with React and useEffect hooks
- my api needs time to process a request, how can I use React + SWR to continue checking on the status?
- How to call loading function with React useEffect only once
- ReactJS: how to call useEffect hook only once to fetch API data
- How to load the google maps api <script> in my react app only when it is required?
- How to make the API call and display it in React JS using React Table and Axios?
- How can I improve the react performance if I have many text inputs (Hooks) in a form?
- How can I reuse the API data for all the pages in react js
- React : How to stop re-rendering component or making an API calls on router change for the same route
- Invalid hook call. Hooks can only be called inside of the body of a function component when i call useQuery in useEffect
- React: How can I call a method only once in the lifecycle of a component, as soon as data.loading is false
- How can I make a request to an API based on the response from another request? React Hook "useSwr" cannot be called inside a callback
- React hooks useEffect call API second time and first time calling API response also returning
- How to centralize the error handling for API calls in react (with Axios)
- How to make useEffect hook call the provided effect only if all the elements in inputs change?
- Call useEffect and re-render every time I call the same API
- Make 2nd API calls when all contents are loaded (lazy loading) from the first API call in React js
- Can I use mock data and proxy api data at the same time in my react project when using node express as a proxy server?
- How can I dynamically change the baseURL of my RTK Query api only for a specific group of injected endpoints?
- How can I call a useEffect only once after everything loads from redux useSelector hooks?
- How to fix 'Hooks can only be called inside the body of a function component' error in React custom hook?
- Invalid hook call. Hooks can only be called inside... how to fix this maintaining the react class component
More Query from same tag
- Click Through a <Canvas/> Element but detect hover
- How to refactor code inside switch statement using react?
- Mapbox & D3: How to create proper color scaling?
- How to implement offcanvas on selected breakpoint on react router dom?
- Does React make a clone of your object when you use the set function?
- Typescript React type argument of type not assignable to parameter of type
- Send variables from one class to routes.js (without props)
- Mocking a React Component using Jest
- Cannot read property of object
- Error callback using echo-laravel and react
- How can I use CSS Pseudo-elements styling inside React JSX to pass variables?
- How to get image filename from Firebase Storage?
- How do I forward a cookie using fetch in getServerSideProps?
- How to connect frontend to json data on heroku
- Razzle, IE11 and HappiJS bundling
- Extending AWS Amplify Auth components in typescript
- redux-promise use 'then()' after dispatching action
- Correct way of error handling in React-Redux
- how to add external library to reactjs?
- Styling individual child component in React
- How to update a react component's state from another file?
- react-router-dom "No match 404" get rendered when going to a path with "useParams"
- React Tutorial history map (step, move)
- Typing an array of objects as props in React
- TypeError: Cannot read property 'name' of undefined inside React component used as child inside another parent component
- Cannot seem to change props of component
- Is there a way to line up the boxes
- How to pass child useState to Parent in React? Functional Component
- How to trigger a Pubsub.js event in a jest test for react.js
- How to serve static Image path in img tag with webpack in React JS application