Answers for "react add class to each children"

0

react add class to each children

const StyleInjector = ({ children }) => {
   const StyledChildren = () =>
    React.Children.map(children, child =>
      React.cloneElement(child, {
        className: `${child.props.className} ${PUT_YOUR_CLASS_HERE}`
      })
    );

  return <StyledChildren />;
};
Posted by: Guest on April-28-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language