score:1
Accepted answer
i would break your useeffect to two since they handle different parts of your code, one to dispatch a fetch and the other to massage the data when received.
// this will dispatch the listcontractors action when the userinfo changes
useeffect(() => {
if (userinfo) {
dispatch(listcontractors())
} else {
history.push('/login')
}
}, [userinfo, history])
// this will update the data when contractors is changed
useeffect(() => {
if (contractors) {
const transformedcontractors = contractors.map(contractor => ({
...contractor, // used this to avoid the one-by-one hand written copy.
action: <link classname='text-dark text-center' to={`/contractor/${c._id}`}><morehorizontal /></link>
}));
setdata(transformedcontractors);
}
}, [contractors]);
Source: stackoverflow.com
Related Query
- React DataTable not repopulating after refresh
- React table not repopulating after page refresh
- React does not refresh after an update on the state (an array of objects)
- React - not refresh page after post with error response
- React component not render anything, except after I refresh page
- Highchart React not rendering heat map after refresh its throwing error
- window.Calendly.initInlineWidget is not defined on first load but works after refresh with useEffect in React and Gatsby
- Refresh value react not value after action
- React Router not working after the page refresh
- React Child Component Not Updating After Parent State Change
- React router 4 does not update view on link, but does on refresh
- React router not working after building the app
- React Intl FormattedNumber with the currency symbol before, not after
- React production router 404 after deep refresh firebase
- React Context api - Consumer Does Not re-render after context changed
- React + Redux, How to render not after each dispatch, but after several?
- React - What's the best practice to refresh a list of data after adding a new element there?
- React Router 4.x - PrivateRoute not working after connecting to Redux
- How to keep React components state after browser refresh
- React Mobx - component not updating after store change
- CSS styles disappear after refresh in React app
- React not rerendering after mobx observer change
- Jquery Datatable Buttons Not Showing Up On React js
- React does not rerender after setState used in promise
- React component not re-rendering after props change
- React hooks state variable not updating after rerender
- Load third party iframe in React after page load, so that the iframe does not affect PageSpeed score
- React not re-rendering after array state update
- react - "Reducers may not dispatch actions." after navigating to a route
- React App returns error after refresh
More Query from same tag
- Wrap TextArea default value
- React Button with linkto functionality add option
- I am trying to create a box in React, and it is not working
- React component is re-rendering items removed from state
- Is there a benefit in React useEffect to resolving promises like this?
- getting error :Invalid hook call. Hooks can only be called inside of the body of a function in react typescript
- How to change className to element after click on another element in React
- How to set colors in react carbon design chart
- React: How to make store invulnerable for reload?
- How to append a JSON descriptor to res.sendFile() in Express?
- How do i get rid of the vertical line appearing in the AceEditor component?
- Trouble Resizing Both Panes in react-split-pane
- How to change decimal character (.) to (,)
- Can we perform expressions within the curly braces where we pass props value in react
- Check if object of any array exist in an another array, if not exists then push onto another array , or else remove it from another array
- Structuring Sidebar in React
- D3 Selection always returns all items after enter() regardless of whether they are new or not
- React Router 5. Component not rendered after redirect
- How to rewrite this double arrow function
- Chrome Extension: Refused to execute inline script, but no inline scripts present?
- NextJS Link Calling Function and Redirect Rather than Route
- block a button until the user accepts the geolocation react.js
- Check Every 8 Numbers in ES6/React
- React.js: Combining properties from an Array of Objects
- How to give api call once and remove the event listener, once you reached the bottom of page?
- Take input value from input and add to state
- Employee.map is not a function
- React: how to get Material UI's grid spacing to work?
- Why does React-Bootstrap duplicate custom classNames in element?
- In React-Router docs, what does this paragraph mean in the "Index Routes" section?