Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

react.children

import React from 'react';

type Props = {
  children: JSX.Element[] | JSX.Element;
  margin: number;
};

export default function Stack({ children, margin }: Props) {
  function wrapChildren() {
    return React.Children.map(children, (child) =>
      React.cloneElement(child, { style: { ...child.props.style, marginBottom: `${margin}px` } }),
    );
  }

  return <>{wrapChildren()}</>;
}
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
9+2 =