Both MapStateToProps and useSelector work with similiar callback store => store.group
Is it safe to mutate those values for example in MapStateToProps like this:
const mapStateToProps = store => {
const { group, level } = store;
let { group } = store;
if (level > 50) {
group = `${group}-admin`;
}
return { group };
};
or in useSelector:
const group = useSelector(store => {
const { group, level } = store;
let { group } = store;
if (level > 50) {
group = `${group}-admin`;
}
return { group };
});
And with useSelector it could actually be done inside the component too like this:
let [group, level] = useSelector(store => [store.group, store.level);
if (level > 50) {
group = `${group}-admin`;
}
...
My co-worker did something like this and I'm not sure if you are supposed to use let
in there. I'm just interested if that is acceptable way to deal with this or if that causes problems? I don't need a different solution for it. I know how to do it with using const
instead.