How useStoreState is referring values in react?

482 Views Asked by At

I am pretty new to react and easy-peasy, I am stuck with one implementation with useStoreState.

I just want to understand how the useStoreState and useStoreAction work in the below code and how state.AdminCompanyInfo and action.AdminCompanyInfo are getting resolved.

I don't find any simple-to-understand example. Please help.

here is the code

    const AdminCompanyInfo = () => {
      var userType = isDesignerUser ? 1 : 2;
      const [hideInactiveUser, setHideInactiveUser] = useState();
      const {
        roles: { data: roles },
        companyUsers: state,
        inactiveUserSetting: { response: orgSetting },
      } = useStoreState(state => state.AdminCompanyInfo);

      const {
        companyUsers: { fetch },
        companyUsers: actions,
        roles: { fetch: fetchRoles },
        inactiveUserSetting: { update: updateOrgSetting },
      } = useStoreActions(actions => actions.AdminCompanyInfo);

      useEffect(() => {
         fetchRoles(userType);
         fetch();
      }, []);
    }
0

There are 0 best solutions below