score:2
Accepted answer
If the interviews are fetched asynchronously within Query
, an easy fix might be:
- introduce a new callback prop
onInterviewsReady
to theQuery
component - let
Query
call this callback in an effect (useEffect
) as soon as the interviews are ready- not using an effect would still cause a foreign component's state to change while rendering
Query
, which yields the warning
- not using an effect would still cause a foreign component's state to change while rendering
- implement the callback by the hosting component
HomePage
with a function likeconst onInterviewsReady = interviews => setPreLaunch(interviews.length < 1);
and pass it toQuery
- if you face unnecessary re-renders, you might want to ensure your callback reference is stable by modifying either
- the host component (
HomePage
): wrap your callback definition inuseCallback
before passing it to the consuming component - the consuming component (
Query
): wrap your passed callback prop inuseRef
and call the ref's current value in the effect instead of the prop's value
- the host component (
Source: stackoverflow.com
Related Query
- Getting error "Cannot update a component while rendering a different component". What is the correct way to achieve what I'm attempting?
- Cannot update a component while rendering a different component warning
- Cannot update a component (`App`) while rendering a different component
- Warning: Cannot update a component while rendering a different component. ReactJS
- Warning: Cannot update a component (`App`) while rendering a different component
- Warning: Cannot update a component (`App`) while rendering a different component (`C2`)
- Cannot remove from my shopping cart (Cannot update a component while rendering a different component)
- Warning: Cannot update a component (`ConnectFunction`) while rendering a different component (`Cart`)
- Cannot update a component (`App`) while rendering a different component (`UserTable`)
- React - Warning: Cannot update a component (`PrivateRoute`) while rendering a different component (`Modules`)
- cannot update a component (yyy) while rendering a different component (yyy)
- Error: Cannot update a component (`AppProvider`) while rendering a different component (`Unknown`)
- Cannot update a component while rendering a different component
- Warning: Cannot update a component (`App`) while rendering a different component (`History`)
- Warning: Cannot update a component while rendering a different component. ReactRedux.Consumer
- React-Bootstrap modal not closing. Error: Cannot update a component (`OnboardPage`) while rendering a different component
- React - Maximum update depth exceeded / Cannot update a component while rendering a different component
- Struggling in passing data from Child to Parent React Component. Cannot update a component (`App`) while rendering a different component (`Table`)
- Cannot update a component (`BrowserRouter`) while rendering a different component (`Login`)
- State management - Cannot update a component (`Provider`) while rendering a different component
- Cannot update a component while rendering a different Component - ReactJS
- React Route Warning: Cannot update a component (`App`) while rendering a different component (`Context.Consumer`)
- I have this error that say "Cannot update a components while rendering a different component" when I run react.js code
- Can not update a component while rendering a different component
- React "Cannot update a component (`BrowserRouter`) while rendering a different component" warning when registering a new user using firebase
- Can Redux cause the React warning "Cannot update a component while rendering a different component"
- Iam getting a error while rendering a component in the main component using react js
- React Warning: Cannot update a component from inside the function body of a different component
- redux-form warning Cannot update a component from inside the function body of a different component
- React-redux Getting error while rendering post in TypeError:Cannot read property 'map' of undefined but console having all posts
More Query from same tag
- Create a search bar in Firestore retrieved data in React and add a functionality of Edit/Update & Delete buttons
- Creating a dynamic header UI with React and Material UI
- Print out JSON data in React
- I cant use java script on flutter
- React: Child State isn't updating after Parent state gets Updated
- Which event to use when React app finishes loading
- How override Material UI Popover CSS classes in Select component in React
- How to enforce Typescript to check that all keys in an object are present in array, where said keys are used as a value?
- MUI Custom named options in palette - Property 'primary' does not exist on type 'TypeBackground'
- Bootstrap vs Material UI for React?
- How do I get the Id when clicked on the first row in React JS?
- Why my custom hook causes infinite data refetching?
- Destructuring object REACT
- React: How to reuse components with their own dataset?
- React / TypeScript - Type '{ index:number}' is missing the following properties from type 'IList': length, pop, push, concat, and 26 more
- Redux: where should we put initialize state for react app
- I can't find a way to pause a countdown Timer in React ( Clear Interval doesn't seems to work)
- Uncaught TypeError: store.getState is not a function
- Material UI DatePicker set to Required
- How to make lodash debounce work with multiple dependencies of useCallback in React
- how to render React components with props from client
- Check if page has on link to add class on it
- How can I mock an imported React hook/module and test that it's being called properly on different test cases using Jest
- React JSX returning TypeError: Cannot read property of undefined
- Firebase .push() attempting to add to DB, but fails?
- Cannot read property 'props' of undefined (React)
- Reactjs website with admin parts
- Test onClick of a button is called when there is no props passed down to it using testing library react and jest
- Typescript input onchange event.target.value
- Setting Page Title with React-Router-Config