absent-sapphire
absent-sapphire9mo ago

add custom Sider menuItem in a separate file

I've a customSider where I have successfully insert my own menu item in. useEffect(() => { const existingIndex = menuItems.findIndex(item => item.key === siderMenuItems.key);
if (existingIndex !== -1) { // If an item with the same key exists, replace it menuItems[existingIndex] = siderMenuItems; } else { // If not, push the new item menuItems.push(siderMenuItems); } }, [menuItems, siderMenuItems]); This is my siderMenuItems.ts import React from 'react'; import { UnorderedListOutlined, DashboardOutlined, LogoutOutlined } from '@ant-design/icons'; export const siderMenuItems = [ { icon: <DashboardOutlined />, label: 'Dashboard', route: '/', key: 'dashboard', name: 'DashboardResource', children: [], }, { icon: <UnorderedListOutlined />, label: 'Canvases', route: '/canvases', key: '/canvases', name: 'canvases', children: [], canDelete: false, canCreate: false, canEdit: false, canShow: false, list: '/canvases', }, // Add other menu items as needed ]; But when I add the icon in the error appears: 'DashboardOutlined' refers to a value, but is being used as a type here. Did you mean 'typeof DashboardOutlined'?ts(2749)
5 Replies
kapa.ai
kapa.ai9mo ago
Hi @lukevo.. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The error you're encountering is a TypeScript error. It's saying that DashboardOutlined is being used as a type, but it's actually a value. In your siderMenuItems.ts file, you're using DashboardOutlined as a React component, which is correct. The error might be coming from somewhere else in your code where you're incorrectly using DashboardOutlined as a type. Please check your code to ensure that you're not using DashboardOutlined or any other icon components as a type. If you're still having trouble, you might want to check out the Refine documentation (https://refine.dev/docs) or ask for help in the Refine Discord community (https://discord.com/channels/837692625737613362/1121423983812812810). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai9mo ago
<@582491401715974144> kapa.ai is still learning and improving, please let us know how it did by reacting below
absent-sapphire
absent-sapphire9mo ago
@kapa.ai importReactfrom'react';import{UnorderedListOutlined,LogoutOutlined,DashboardOutlined}from'@ant-design/icons';import{TreeMenuItem}from'@refinedev/core/dist/hooks/menu/useMenu';exportconstsiderMenuItems:TreeMenuItem=[{icon:<DashboardOutlined/>,label:'Dashboard',route:'/',key:'dashboard',name:'DashboardResource',children:[],},{icon:<DashboardOutlined/>,label:'Canvases',route:'/canvases',key:'/canvases',name:'canvases',children:[],canDelete:false,canCreate:false,canEdit:false,canShow:false,list:'/canvases',},//Addothermenuitemsasneeded];importReactfrom'react';import{UnorderedListOutlined,LogoutOutlined,DashboardOutlined}from'@ant-design/icons';import{TreeMenuItem}from'@refinedev/core/dist/hooks/menu/useMenu';exportconstsiderMenuItems:TreeMenuItem=[{icon:<DashboardOutlined/>,label:'Dashboard',route:'/',key:'dashboard',name:'DashboardResource',children:[],},{icon:<DashboardOutlined/>,label:'Canvases',route:'/canvases',key:'/canvases',name:'canvases',children:[],canDelete:false,canCreate:false,canEdit:false,canShow:false,list:'/canvases',},//Addothermenuitemsasneeded]; Why?
kapa.ai
kapa.ai9mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- It seems like you've pasted the same code block twice, and it's a bit difficult to understand your question. However, I can see that you're trying to define custom menu items for your sidebar in Refine. Your siderMenuItems array looks correct. You're defining two menu items: "Dashboard" and "Canvases". Each item has an icon, label, route, key, name, and other properties. If you're encountering an error, it would be helpful to know what the error message is. If you're asking why you need to define siderMenuItems, it's because Refine allows you to customize the sidebar navigation of your application. By defining siderMenuItems, you're specifying what menu items should appear in the sidebar, what their labels and icons should be, and what routes they should link to. If you need more information on how to customize the sidebar in Refine, you can refer to the official documentation (https://refine.dev/docs/faq/). If you're encountering a specific error, please provide the error message for more targeted help. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai9mo ago
<@582491401715974144> kapa.ai is still learning and improving, please let us know how it did by reacting below