如何优化 useSelector() 反应中的状态值

how to optimize the state value in useSelector() react

请告诉我如何优化 useselector 的更好方式:

 const {
    addressList,
    deleteUserAddress,
    favouriteAddress,
    userAddressAfterUpdate,
    details,
    tokens,
  } = useSelector((state: RootState) => ({
    addressList: state?.address?.addressList,
    deleteUserAddress: state?.address?.deleteUserAddress,
    favouriteAddress: state?.address?.favouriteAddress,
    userAddressAfterUpdate: state?.address?.userAddressAfterUpdate,
    details: state.user.details,
    tokens: state.user.tokens,
  }));

也许你可以:

 const {
    address,
    user
  } = useSelector((state: RootState) => ({
    address: state?.address,
    user: state?.user
  }));

然后在需要时您可以调用 address.addressListuser.tokens