score:0
maybe try something like this
const fetchapi = async () => {
const api = await fetch("https://randomuser.me/api");
const json = await api.json();
let results = json.results;
// here you get the old data and pushing the results into data
data.push(results)
// and setdata to data that has (data + results)
setdata(data);
};
also if you want to have your data after refreshing your browser , you may need to store data
in localstorage and get the initial data from that
Source: stackoverflow.com
Related Query
- here is an API that changes after some time I want previous data to be stored in an array and latest data too I dont how to figure this out?
- Fetching data first time from API endpoint it return empty array, after that return array with real information
- How to open a page in new tab on click of a button in react? I want to send some data to that page also
- Printing variable after fetching data from API gives empty and after that filled value is printed
- Data from API call are stored in a Array but when i try to use that array in a function for further use it shows that array is empty . why?
- I want a simple authentication with bearer token and rest api which should be stored in local storage and be refresh in given time in REACT
- How is it possible that after API call and setState, some elements of the same object are accessible, while others aren't?
- I want to change the API request based on button click. The number in the API changes and different data loads but component does not rerender
- My firebase data disappears after some time
- How can I ensure that a React component is loaded only after some API call has been made?
- i want to load first element from api initially , but after making change to other user data the component goes back to first element data
- i have data in my shopify api i want to use that data in my reactjs app how do i do that
- How to fetch API and store some value and then fetch again with that stored value in React
- How to perform search on data that is stored in context api in reactjs?
- Authentication cookie disappears in react SPA after some time
- REACT - Set initial data in Formik Form after fetching from API
- How to generate a unique id automatically for the data that is posted to an API server using axios library in redux
- React Context : Get Data from API and call API whenever some events happens in React Component
- How to set expiration time for data stored in ReactJs localStorage
- React-Redux + Redux-Thunk on functional component. Update UI after data is fetched from API
- How to store data from API so that it can be accessible in other components
- Is there an accessible way of telling that some part of UI can redirect to other page if some asynchronous condition is resolved after clicking link?
- How to set default value of react-select after getting data from API
- How to update the state after a data update through an API request in React?
- React is not updating the UI after receiveing data from the API call (using hooks)
- i want to Call a function after previous function is complete reactjs
- infinite api calls in componentDidUpdate(prevProps) despite conditional that compares current prop with previous prop
- 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?
- react-google-maps/api Avoiding re-render of Map after some state changes
- making second api call after getting data from the first api
More Query from same tag
- performance: connecting to the Redux store vs passing data through props
- How can I update state value immediately in React js?
- Why stream title is not rendering when whole stream object is returned from mapStateToProps?
- How to get value from localstorage react
- How to display base64 image in React Js?
- My react app is giving an error of "action undefined"
- Webstorm doesn't recognize prop type of ...props
- Creating anchor with onClick that React handles
- Which is Best .toJS() vs .toJSON() in immutable js?
- Difference between Material-Ui and Material-Ui-Next
- Setting state in React Enzyme unit test which I pass through props
- Render a radio button as already selected on page load - React js
- How can i get postmessage data from react?
- filter api data in reactjs
- Make a tree view from data
- redux saga deleting functionality
- How to extend a component to add default props in React/TS
- Jest - assert async function throws test fails
- How to keep previous values when updating array in React with useState
- How to test a react component that is dependent on useContext hook?
- How to validate field when rendering same field multiple time with different name id in redux form
- React app doesnt work in safari browser? SyntaxError
- TypeError: Cannot read property 'location' of undefined react error on using 'window'
- Massive spike in YouTube Data API queries
- React.js: Access Overall App State from a Standalone Component
- how to show date below day of month in react?
- Reactjs - How to display imported images with Reactjs photo gallery
- why does the component render 3 times?
- why useEffect is called twice when using useCallbackRef from use-callback-ref
- setState doesn't set state properly when used in array map function (we aren't using hooks its old project)