{"size": 685, "ext": "js", "max_stars_repo_path": "packages/react-jsx-highcharts/src/components/Axis/AxisTitle.js", "max_stars_repo_name": "veloek/react-jsx-highcharts", "max_stars_repo_stars_event_min_datetime": "2017-07-05T15:11:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T05:11:49.000Z", "max_issues_repo_path": "packages/react-jsx-highcharts/src/components/Axis/AxisTitle.js", "max_issues_repo_name": "veloek/react-jsx-highcharts", "max_issues_repo_issues_event_min_datetime": "2017-07-05T20:16:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T10:06:02.000Z", "max_forks_repo_path": "packages/react-jsx-highcharts/src/components/Axis/AxisTitle.js", "max_forks_repo_name": "veloek/react-jsx-highcharts", "max_forks_repo_forks_event_min_datetime": "2017-08-03T08:13:16.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T21:38:30.000Z"}
{"max_stars_count": 412, "max_issues_count": 346, "max_forks_count": 125, "avg_line_length": 19.5714285714, "max_line_length": 70, "alphanum_fraction": 0.5547445255}
import { useEffect, memo } from 'react';
import useAxis from '../UseAxis';

const AxisTitle = memo(({ children: text, axisId, ...restProps }) => {
  const axis = useAxis(axisId);

  useEffect(() => {
    if (axis) {
      updateAxisTitle({ text, ...restProps }, axis);
    }
  });

  useEffect(() => {
    return () => {
      if (axis) {
        try {
          updateAxisTitle({ text: null }, axis);
        } catch {
          // ignore as axis might have been already unmounted
        }
      }
    };
  }, [axis]);

  return null;
});

const updateAxisTitle = (config, axis) => {
  axis.setTitle(config, true);
};

AxisTitle.displayName = 'AxisTitle';

export default AxisTitle;
