score:1
the error is because on initial render phase, you render the component with setisdashboard(true);
, usually, you want to do it on mount (useeffect
with empty dep array).
there is an initial render phase, then mount phase, see component's lifecycle diagram.
be sure that setisdashboard
is persistent, meaning it is created by react api (like usestate
).
or its memoized with usememo
/usecallback
, or you will get inifite loop because on every render a new instance of setisdashboard
will be created and the dep array ([setisdashboard]
) will cause another execution.
const protectedroute = ({ component }) => {
const { setisdashboard } = usecontext(dashboardcontext);
// make sure `setisdashboard` persistant
useeffect(() => {
setisdashboard(true);
}, [setisdashboard]);
...
};
score:0
the error is because you can't set state when you are rendering:
dashboardcontext.setisdashboard(true);
is probably the problem.
you don't post your stack trace or line numbers so it's hard to tell exactly what the issue is:
Source: stackoverflow.com
Related Query
- Cannot update a component (`App`) error in component
- Cannot update a component while rendering a different component warning
- React Warning: Cannot update a component from inside the function body of a different component
- Why does this error exist: "Invariant Violation: Cannot update during an existing state transition"
- ReactJS deploy app error Cannot copy to clipboard: Command failed: xsel --clipboard --input
- Cannot update a component (`App`) while rendering a different component
- Cannot update during an existing state transition in stateless component
- Error : Can't perform a React state update on an unmounted component
- Cannot update during an existing state transition error in React
- Getting error "Cannot update a component while rendering a different component". What is the correct way to achieve what I'm attempting?
- Bootstrap Modal causes 'Uncaught TypeError: Cannot convert undefined or null to object' error in Heroku with Rails 6 app
- Error Cannot read property 'left' of undefined in React Semantic UI Popup with Styled Component
- react component error Cannot read property of undefined
- redux-form warning Cannot update a component from inside the function body of a different component
- React: Axios Error "Error: Network Error", My react app cannot receive axios.post response
- Error "Maximum update depth exceeded. This can happen when a component calls setState inside useEffect"
- My code cannot update nested component
- Router events cause an error while being used on the constructor Warning: Can't perform a React state update on an unmounted component
- Warning: Cannot update a component while rendering a different component. ReactJS
- Cannot Get ReactJS Component to Update
- React App Login Error : Maximum update depth exceeded
- ReactJs error - Warning: setState(...): Can only update a mounted or mounting component
- Create React App Error - Loading PostCSS "postcss-preset-env" plugin failed: Cannot find module 'node:vm'
- I get internal server error while running next js app with styled component
- React Can't perform a React state update on an unmounted component error
- Cannot update during an existing state transition error
- React -- changing state unrelated to component triggers maximum update depth error
- Error "SyntaxError: Cannot use import statement outside a module" when deploying React app with Netlify Functions
- Warning: Cannot update a component (`App`) while rendering a different component
- Using a JSX Component inside a TSX Component cannot compile without throwing an error
More Query from same tag
- Connect state with children components
- Redux Thunk silently fails to update state
- Dynamically adding children of arbitrary types to React components
- Is it possible to keep built-in GridTile styles when image preload is used?
- API Endpoint only allows GET when it should take POST
- Mix blend mode in an svg with gradient colors
- How to get Data info from OpenWeatherMap API 'dt'
- Install reactjs on ubuntu 18.04
- Pass data (prop) from _app.js to getServerSideProps in a page - NextJS, latest version
- Is it ok to modify part of prevState inside setState?
- React onClick function in map function
- How can I unit test a component which dispatches an action in reactjs/redux app?
- how can I reuse the function to update different parts of the state of a React component?
- Accessing return variable of React class component
- React useEffect hook causes DOMException: User activation is required to request permissions
- Pie Chart not rendering React Chart.js
- how do i make my rendered cards responsive?
- How to pass a specific prop when the props can have multiple types in React, Typescript?
- Regular expression for syntax highlighting attributes in HTML tag
- React component socket.io unnecessary connection
- ERROR: Using UNSAFE_componentWillReceiveProps (NextJs / Redux)
- Set correct value for each property in an object
- React Google Identity services
- ReactJS: Change state of child component
- How to define listener argument for provider.on(eventName, listener) for listening a smart contract event with ethers.js?
- How can I stop rendering undefined at the first render time?
- How do I find out what code is causing JavaScript heap out of memory
- How to spy on default prop function in Jest
- Stripe ElementsConsumer with TypeScript: Pass prop?
- Changing multiple props const to class