0

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();
      }, []);
    }
Mayank
  • 1,351
  • 5
  • 23
  • 42
  • Do you know what [hooks](https://reactjs.org/docs/hooks-intro.html) are in React? If not, you should start there and learn about the standard `useState()` and `useEffect()` hooks. Once you understand hooks in general, you can more easily understand the `easy-peasy` documentation for [`useStoreState()`](https://easy-peasy.vercel.app/docs/api/use-store-state.html) and [`useStoreActions()`](https://easy-peasy.vercel.app/docs/api/use-store-actions.html). – Code-Apprentice Apr 27 '22 at 15:25
  • @Code-Apprentice, yes, I am using `useState()` and `useEffect()` , but I don't get the idea how the `companyUsers: state` or `roles: { data: roles },` are getting resolved, I don't find any variable that assigns the value to. That is pretty ambiguous to me. – Mayank Apr 27 '22 at 15:28
  • What do you mean by "how they're getting resolved"? `AdminCompanyInfo` is configured/set/etc in the store somewhere, they're properties in the store. – Dave Newton Apr 27 '22 at 15:35
  • @Mayank Are you familiar with "destructuring syntax"? – Code-Apprentice Apr 27 '22 at 15:41

0 Answers0