Consider both these calls
const loading = useSelector((state) => state.example.loading);
const { loading } = useSelector((state) => state.example);
const { loading } = useSelector((state) => state.example); would make the component cause an unnecessary render whenever the other variable in the example slice changes. This one const loading = useSelector((state) => state.example.loading); wont because it only gets the loading variable.
In an app that I'm cleaning up a group member wrote const { var1, var2, var3....var50 } = useSelector((state) => state.example); and its causing unnecessary renders throughout the app. Instead of rewriting
const var1 = useSelector((state) => state.example.var1);
const var2 = useSelector((state) => state.example.var2);
...
Is there anyway to shorthand this but without causing a render?
playground example:
https://codesandbox.io/s/cool-dew-7pfclw?file=/src/Header.js