1.0.0 • Published 2 years ago

use-child v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

use-child

React hook for getting the type of any nested child component

Install

npm install use-child

Usage

import useChild from 'use-child';

const Car = props => {
  const [wheelExists, WheelComponent] = useChild(props.children, Wheel);
  const [engineExists, EngineComponent] = useChild(props.children, Engine);

  return (
    <div>
      {wheelExists && WheelComponent}
      {engineExists && EngineComponent}
    </div>
  );
};

const Wheel = () => {
  return <div>I am a wheel</div>;
};

const Engine = () => {
  return <div>I am an engine</div>;
};