import useUserModel from '@/store/user';

import React from "react";

export default (props) => {
  const { code, fallback = null, children } = props;
  const [user] = useUserModel();

  const isOk = React.useMemo(() => {
    if (!code) return true;
    if (!user || user.length < 1) return false;

    return user.findIndex((x) => x == code) > -1;
  }, [code, user]);
  return isOk ? children : fallback;
};
