Why does my HomeTypes component unmount and remount every time I use setDrawerOpen? Does a state change inside a component always cause that component to unmount and then re-mount?
import React, { useEffect, useState } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import Drawer from '../../components/DrawerComponent/Drawer';
function HomeTypes() {
const [drawerOpen, setDrawerOpen] = useState(null);
useEffect(() => {
console.log('Home Types Mounted');
return () => {
console.log('Home Types Unmounted');
};
});
return (
<div className={`dashboard-page`}>
<h1 className="dashboard-page-title">
Home Types
<button
className={`btn bright primary`}
onClick={() => {
setDrawerOpen(true);
}}>
<FontAwesomeIcon icon={['fas', 'plus']} />
<span>add home type</span>
</button>
</h1>
<Drawer
drawerOpen={drawerOpen}
closeDrawer={() => {
setDrawerOpen(false);
}}
title="Add Home Type"
drawerContent="Hello World"
/>
</div>
);
}
export default HomeTypes;