I have a question about redux useSelector equality check.
Refer to the React Redux Hook document (https://react-redux.js.org/api/hooks#equality-comparisons-and-updates)
useSelector will do reference comparison to the return value and the previous value, force re-render if result appears to be different
I have a default blog store state like this
searcherParam: {
keyword: '',
categories: [],
tags: [],
},
In the component, I use useSelector to retrieve the value
const searchParam = useSelector(state => state.Blog.searcherParam)
If I dispatch an action to update searcherParam with same value, the component will re-render because the return value is object (shallow compare)
So I retrieve the value by calling useSelector multiple times
const keyword = useSelector(state => state.Blog.searchrParam.keyword)
const categories = useSelector(state => state.Blog.searchrParam.categories)
const tags = useSelector(state => state.Blog.searchrParam.tags)
And I dispatch an action to update searcherParam with same value again
the component will not re-render
The point I can't understand is why component doesn't re-render ?
If useSelector do reference comparison, the categories value (array) should not be the same reference and the tags as well after dispatching
Do I have any misunderstanding ? Thanks
The reason about not re-rendering is because I save the categories (from redux store) via useState.
and use the useState's value to dispatch, so it is same reference...
here is the codesandbox, sorry for stupid question Q_Q