<commit_before>import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';

import config from '../../config';

export default function LocationsSource({ activeParameter, map, children }) {
  const [sourceId, setSourceId] = useState(null);

  useEffect(() => {
    if (!map.getSource(`locations-source-${activeParameter}`)) {
      map.addSource(`locations-source-${activeParameter}`, {
        type: 'vector',
        tiles: [
          `${config.api}/locations/tiles/{z}/{x}/{y}.pbf?parameter=${activeParameter}`,
        ],
        minzoom: 0,
        maxzoom: 24,
        bounds: [-180, -90, 180, 90],
      });
    }

    setSourceId(`locations-source-${activeParameter}`);

    return () => {
      setSourceId(null);
      if (map.getSource(`locations-source-${activeParameter}`)) {
        map.removeSource(`locations-source-${activeParameter}`);
      }
    };
  }, [activeParameter]);

  return (
    <>
      {!!(map && sourceId && map.getSource(sourceId)) &&
        React.Children.map(children, child =>
          React.cloneElement(child, {
            map: map,
            sourceId: sourceId,
          })
        )}
    </>
  );
}

LocationsSource.propTypes = {
  activeParameter: PropTypes.string.isRequired,
  map: PropTypes.object.isRequired,
  children: PropTypes.oneOfType([<commit_msg>Don't remove source<commit_after>import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';

import config from '../../config';

export default function LocationsSource({ activeParameter, map, children }) {
  const [sourceId, setSourceId] = useState(null);

  useEffect(() => {
    if (!map.getSource(`locations-source-${activeParameter}`)) {
      map.addSource(`locations-source-${activeParameter}`, {
        type: 'vector',
        tiles: [
          `${config.api}/locations/tiles/{z}/{x}/{y}.pbf?parameter=${activeParameter}`,
        ],
        minzoom: 0,
        maxzoom: 24,
        bounds: [-180, -90, 180, 90],
      });
    }

    setSourceId(`locations-source-${activeParameter}`);

    return () => {
      setSourceId(null);
    };
  }, [activeParameter]);

  return (
    <>
      {!!(map && sourceId && map.getSource(sourceId)) &&
        React.Children.map(children, child =>
          React.cloneElement(child, {
            map: map,
            sourceId: sourceId,
          })
        )}
    </>
  );
}

LocationsSource.propTypes = {
  activeParameter: PropTypes.string.isRequired,
  map: PropTypes.object.isRequired,
  children: PropTypes.oneOfType([
{'fraction_non_alphanumeric': 0.16699487987396613, 'fraction_numerical': 0.010240252067743205, 'mean_word_length': 2.735294117647059, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2363895', 'n_tokens_mistral': 789, 'n_tokens_neox': 771, 'n_words': 132}