Redux工具包-selectById

Redux工具包-selectById,redux,redux-toolkit,Redux,Redux Toolkit,我尝试使用reduxtoolkit的selectbyId助手方法,但没有成功。有人能帮我吗 类别切片 export const { selectAll:selectCatetories,selectById:selectCategoryById }=categoriesAdapter.getSelectors(state=>state.inventory.categories.categories) 类别成分 const category=useSelector((id)=>

我尝试使用reduxtoolkit的selectbyId助手方法,但没有成功。有人能帮我吗

  • 类别切片

    export const {
     selectAll:selectCatetories,selectById:selectCategoryById
     }=categoriesAdapter.getSelectors(state=>state.inventory.categories.categories)
    
  • 类别成分

    const category=useSelector((id)=>selectCategoryById(id))
    

  • 我确信我的实现有问题

    要获取带有Id的类别,您需要创建一个

    然后,您将能够在React组件中使用选择器挂钩:

    const category = useSelector(selectCategoryEntity(id));
    

    您只需要将状态传递给useSelector函数

    const category = useSelector((state)=>selectCategoryById(state, id))  
    
    const category = useSelector((state)=>selectCategoryById(state, id))