VL
Size: a a a
VL
Д
VL
RK
const User = () => //some HTML
const useUser = () => {
const profile = useSelector(slelectUserProfile);
const user = useMemo(() => <User {...profile} />,[profile.id])
return user;
}
const Main = () => {
const user = useUser();
return <>
...some other cmp
{user}
</>
}
Д
VL
VL
VK
const User = () => //some HTML
const useUser = () => {
const profile = useSelector(slelectUserProfile);
const user = useMemo(() => <User {...profile} />,[profile.id])
return user;
}
const Main = () => {
const user = useUser();
return <>
...some other cmp
{user}
</>
}
RK
VK
RK
VK
RK
VK
RK
VK
RK
RK
const User = () => // some HTML
const UserProfile = () => {
const profile = useSelector(slelectUserProfile);
const user = useMemo(() => <User {...profile} />,[profile.id])
return <>{user}</>;
}
const Main = () => {
return <>
...some other cmp
<UserProfile />
</>
}
VK
However, when an action is dispatched to the Redux store, useSelector() only forces a re-render if the selector result appears to be different than the last result. As of v7.1.0-alpha.5, the default comparison is a strict === reference comparison. This is different than connect(), which uses shallow equality checks on the results of mapState calls to determine if re-rendering is needed. This has several implications on how you should use useSelector().
RK