I'm trying to use the 'useHistory' (from react-router-dom) push method on a function that is called by onClick method. The redirect work fine although i get an error in the console that states:
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
My routing is handled in My App.js as follows:
function App() {
return (
<Container style={{ display: 'flex', flexDirection: 'column' }}>
<Router>
<Row>
<Col>
<div className="tabs">
<Switch>
<Route path='/' exact component={Home} />
<Route path='/staff' component={InsertingStaff} />
<Route path='/students' component={InsertingStudents} />
<Route path='/groups' component={ManageGroups} />
</Switch>
</div>
</Col>
</Row>
</Router>
</Container>
);
}
and the component that pushes to the router after onClick event:
function GroupsTree() {
let history = useHistory();
function handleClick(group_item) {
localStorage.setItem('selected_group', JSON.stringify(group_item))
history.push("/groups");
}
const styles = {
lines: {
color: '#0064FF',
height: '40px'
},
node: {
backgroundColor: '#0064FF',
border: '1px solid #1890ff',
},
text: {
color: '#FFFFFF',
}
};
const StyledTree = withStyles(styles)(Tree);
return (
<TransformWrapper doubleClick={{ disabled: true }} options={{ limitToBounds: false, minScale: 0.6 }} defaultScale={1}>
<TransformComponent>
<StyledTree data={data} direction={true} onClick={item => {
handleClick(item);
}}></StyledTree>
</TransformComponent>
</TransformWrapper>
)
}
any idea on what is causing the error/warning?
Tree
coming from? – Sagiv b.gTransformComponent
is doing any animations, is this also a third party? – Sagiv b.greact-zoom-pan-pinch
"fault" i would try running the app without it and see if i get the same warning. – Sagiv b.g