문제
MUI의 @toolpad/core 레이아웃을 사용하다가, Account에 slots을 커스텀해야해서 하는데, 공식문서대로 적용을 해도 적용이 안되는 문제가 발생했다
공식문서 : https://mui.com/toolpad/core/react-account/#slots
Account - Toolpad Core
A component that renders an account management dropdown for your application.
mui.com
해결
챗GPT한테도 계속 물어보고 이상한 답변만 받고, 이와 관련된 구글링을 하는데도 하나도 안떠서 뭐지 뭐지 하다가 아래의 링크를 보고 혹시나 해서 아래처럼 적용시켰는데 적용이 되었다
https://stackoverflow.com/questions/79047504/mui-dashboardlayout-default-state
MUI DashboardLayout Default State
I am using the DashboardLayout from MUI on my page https://mui.com/toolpad/core/react-dashboard-layout/ https://mui.com/toolpad/core/api/dashboard-layout/#slots I'm trying to set the sidenav bar to
stackoverflow.com
전코드
const CommonLayout = () => {
const navigate = useNavigate();
const [pathname, setPathname] = useState('/');
const { user } = useUserStore();
const { isLoggedIn, login, logout } = useAuth();
// Remove this const when copying and pasting into your project.
const demoWindow = typeof window !== 'undefined' ? window : undefined;
useEffect(() => {
user &&
setSession({
user: {
name: user.name,
email: user.email
}
});
}, [user]);
return (
<AppProvider
navigation={NAVIGATION}
branding={LOGO}
router={router}
theme={demoTheme}
window={demoWindow}
// authentication={authentication}
// session={session}
>
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
<Account
slots={{
menuItems: CustomMenu
// 왜 적용이 안되는것인가........
}}
/>
{/* 사이드바 접히는부분 없애는 옵션 */}
<DashboardLayout disableCollapsibleSidebar>
<DemoPageContent pathname={pathname} />
{/* 안에 렌더링 될 컴포넌트들 */}
{/* 환경설정 */}
{pathname === '/settings/system' && <SystemSettings />}
{pathname === '/settings/item-management' && <ItemManagement />}
{pathname === '/settings/user-management' && <UserManagement />}
{pathname === '/settings/permission-management' && <PermissionManagement />}
</DashboardLayout>
</SessionContext.Provider>
</AuthenticationContext.Provider>
</AppProvider>
);
};
후코드
AccountCustomMenu라고 새로 만들어서 거기에 Account태그를 넣고, 이를 DashboardLayout에 slots에 toolbarAccount옵션에다가 전달을 했더니 적용이 되었다!!
const CommonLayout = () => {
const navigate = useNavigate();
const [pathname, setPathname] = useState('/');
const { user } = useUserStore();
const { isLoggedIn, login, logout } = useAuth();
// Remove this const when copying and pasting into your project.
const demoWindow = typeof window !== 'undefined' ? window : undefined;
useEffect(() => {
user &&
setSession({
user: {
name: user.name,
email: user.email
}
});
}, [user]);
const AccountCustomMenu = () => {
return (
<Account
slots={{
menuItems: CustomMenu
}}
/>
);
};
return (
<AppProvider
navigation={NAVIGATION}
branding={LOGO}
router={router}
theme={demoTheme}
window={demoWindow}
// authentication={authentication}
// session={session}
>
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
{/* 사이드바 접히는부분 없애는 옵션 */}
<DashboardLayout
disableCollapsibleSidebar
slots={{
toolbarAccount: AccountCustomMenu
// 유저아이콘 클릭시, 나타나는 커스텀 메뉴!!!⭐️
}}
>
<DemoPageContent pathname={pathname} />
{/* 안에 렌더링 될 컴포넌트들 */}
{/* 환경설정 */}
{pathname === '/settings/system' && <SystemSettings />}
{pathname === '/settings/item-management' && <ItemManagement />}
{pathname === '/settings/user-management' && <UserManagement />}
{pathname === '/settings/permission-management' && <PermissionManagement />}
</DashboardLayout>
</SessionContext.Provider>
</AuthenticationContext.Provider>
</AppProvider>
);
};
완료 화면
'2. FrontEnd > React' 카테고리의 다른 글
[ React ] 다국어 코드 중복 제거하는 리팩토링 후기 (0) | 2024.11.20 |
---|---|
[ React ] useState 초기값 설정 에러 (0) | 2024.10.11 |
[ React ] 로그인 안될경우, 로그인 페이지로 리다이렉트 (+예외처리) (0) | 2024.10.02 |
[ React ] 회원약관 두개이상의 토글이 true일때, 다음 버튼 활성화 (1) | 2024.09.23 |
[ React ] 이메일 유효성 검사 후 에러메세지 띄우는 로직 (onBlur 이벤트) (0) | 2024.09.20 |