{"size": 596, "ext": "js", "max_stars_repo_path": "src/LdFeature.js", "max_stars_repo_name": "Brianzchen/react-ld", "max_stars_repo_stars_event_min_datetime": "2021-06-05T00:11:33.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-05T00:11:33.000Z", "max_issues_repo_path": "src/LdFeature.js", "max_issues_repo_name": "Brianzchen/react-ld", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/LdFeature.js", "max_forks_repo_name": "Brianzchen/react-ld", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 18.625, "max_line_length": 46, "alphanum_fraction": 0.6627516779}
// @flow
import * as React from 'react';

import Context from './Context';

type Props = {|
  children?: React.Node,
  feature: string,
  deprecation?: boolean,
  fallback?: React.Node,
|};

const LdFeature = ({
  children = null,
  feature,
  deprecation = false,
  fallback = null,
}: Props): React.Node => {
  const client = React.useContext(Context);
  const { flags } = client;

  if (!flags) return fallback;

  const isEnabled = !!flags[feature];
  if (!isEnabled && !deprecation) return null;
  if (isEnabled && deprecation) return null;

  return children;
};

export default LdFeature;
