score:0
const currList = useRef([]);
useEffect=(()=>{
const fetchShips = async () => {
const response = await request(gql`
{
ships {
name
home_port
image
}
}
`);
console.log("request response", response.data);
// setCurrList(response.data);
if(response)
currlist.current = response.data
console.log("currlist:", currList);
};
fetchShips()
// Also as far as I know ,you should use useEffect like this
},[])
//... codes
return(
//... codes
currList.current.map(...
)
//... codes
score:1
useEffect(() => {
console.log("List is updated", currList);
}, [currList]);
Source: stackoverflow.com
Related Query
- Can't Update state after fetch request
- Need to Update State Synchronously after Fetch API Request
- React - How to Update State After AJAX Request
- How to re-render component after fetch request and state change?
- Update state after axios POST request
- How to update the state after a data update through an API request in React?
- Update state after axios POST request instead of page refresh
- React - Ways to update state after ajax post request
- Cant use dot or bracket notation to access keys or data in json/javascript object saved to state after fetch
- Update List of users Table after POST fetch request
- Update State component after fetch Redux
- Unable to update state variables after fetch in ReactJS
- Performing a fetch request only on state update
- React: Update a component's state after fetch delete
- How to add objects retrieved from fetch request to the state array in React and then update the view?
- Cant Update The state after getting data from the input React js
- Can't perform a React state update on an unmounted component after API fetch
- update the state of my component with the response data after Post request with axios
- Axios request after state update in React (to use state value in url)
- Table Component is not re-rendered after state update
- React does not refresh after an update on the state (an array of objects)
- React not re-rendering after array state update
- React setState() not updating state after $.ajax() request
- How to update React component after changing state through redux?
- How to test state update and component rerender after async call in react
- React & Reselect selector claims state is the same after update
- React (Native) Context API Causes Stack Navigator (React Navigation 5) to re-render after state update
- React Redux store state update process after saving to database
- Can't perform a React state update on an unmounted component with fetch POST method
- How does React update a component and its children after a state change?
More Query from same tag
- Display proper html content in react. Content is Dynamic from Database
- Using setInterval in React delays component render
- NextJS getStaticProps() not updating from form values
- Component is rendered before i can redirect the route. How can I mitigate rendering?
- Using babelify in Gulp, importing css results to unexpected token "{"
- How to catch error in NodeJS and send own error code?
- Storybook default selection control value
- Trouble with Grid Layout in React Material UI
- React - how to pass a prop into a class function call that is then accessed in componentDidMount function
- Preventing components to mount on each render with React Router
- how can export material-ui table to CSV?
- Implementing promise in react
- How to map inside of the map component?
- react populate modal from graphql
- how to style disabled antd picker
- How do I position an element in middle of a page and then make it sticky and go to top?
- session flush automaically in express-session
- Fastify giving a react prop to a render with next.js
- React setState on another element
- Render a simple list in React with promises
- React useRef combined with useEffect not rendering initial values
- React CRA: Preload fonts from fonts folder
- babel core 7.4.4, using all polyfills by default
- React: Is there a way to access component state from function in another file?
- TypeError: Cannot read property 'map' of undefined jest.js
- react map es6 arrow function doesn't work
- React app and Next js under same Production fe url
- how to pass props into component from route array in react
- React - dynamic input fields based on count
- CSS Flex - Set same width with TailwindCSS