{"size": 1058, "ext": "js", "max_stars_repo_path": "src/hooks/useProskomma.js", "max_stars_repo_name": "Valyukhov/proskomma-react-hooks", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/hooks/useProskomma.js", "max_issues_repo_name": "Valyukhov/proskomma-react-hooks", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/hooks/useProskomma.js", "max_forks_repo_name": "Valyukhov/proskomma-react-hooks", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.5106382979, "max_line_length": 94, "alphanum_fraction": 0.6332703214}
import {
  useState, useCallback, useMemo,
} from 'react';
import PropTypes from 'prop-types';

import { UWProskomma, randomString } from '..';

/**
 * This is the hook.
 */
export default function useProskomma({ verbose }) {
  // manage two states required since they need updating at different times.
  const [stateId, setStateId] = useState(''); // needs to start out defined and type is string
  const [errors, setErrors] = useState([]);

  const newStateId = useCallback(() => {
    const _stateId = randomString();

    if (verbose) {
      console.log('useProskomma.newStateId(): ' + _stateId);
    };
    setStateId(_stateId);
  }, [verbose]);

  const proskomma = useMemo(() => {
    let _proskomma;

    try {
      _proskomma = new UWProskomma();
      newStateId();
      // import frozen proskomma state
    } catch (e) {
      setErrors([e]);
    };
    return _proskomma;
  }, [newStateId]);

  return {
    proskomma, stateId, newStateId, errors,
  };
};

useProskomma.propTypes = {
  /** console log details */
  verbose: PropTypes.bool,
};
