Replies: 1 comment 3 replies
-
useSelector only selects state already in store, it won't kick off any fetching processes. you should continue to use the useQuery hook for that. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
i used useSelector, but it can't get data.
My program part:
const ordermgmtAdapter = createEntityAdapter()
const initialState = ordermgmtAdapter.getInitialState()
export const {
useGetOrdersQuery,
useUpdateOrderMutation,
} = OrderMgmtApiSlice
export const selectOrderResult = OrderMgmtApiSlice.endpoints.getOrders.select();
const selectOrdersData = createSelector(
selectOrderResult,
orderResult => orderResult.data
)
export const {
selectAll: selectAllOrders,
} = ordermgmtAdapter.getSelectors(state => selectOrdersData(state) ?? initialState)
in other compoent, i used const Orders = useSelector(selectAllOrders); to get data. It cannot get data,
but i used below. orderdata can get data.
const {
data: orderdata,
isSuccess,
isLoading,
isError,
error,
refetch
} = useGetOrderQuery()
my progam using package:
"@reduxjs/toolkit": "^2.2.8",
"react-redux": "^9.1.2",
"redux-persist": "^6.0.0",
nodejs: 20.11.1
Beta Was this translation helpful? Give feedback.
All reactions