0

I using Buttongroup component where i want to props.children inside Buttongroup Component.I'm able to achieve only one button , how do i loop or use 3buttons inside Buttongroup. Please help . Below is my code. Any help would be appreciated . With my below code i'm getting only one button. I'm expecting image result

enter image description here

import * as React from "react";
import Button from "@mui/material/Button";
import ButtonGroup from "@mui/material/ButtonGroup";

export const mycomponent = (props) => {
  const {  children, } = props;
  return (
     <ButtonGroup{...props}>
          <Button {...props}>{props.children}</Button> 
           <Button {...props}>{props.children}</Button> 
            <Button {...props}>{props.children}</Button> 
     </ButtonGroup> 
  );
};
mycomponent.propTypes = {
 children: PropTypes.node, 
};
mycomponent.defaultProps = {
 children: [],
};
user3448925
  • 199
  • 1
  • 10

1 Answers1

1

Maybe you need something like this:

import * as React from "react";
import Button from "@mui/material/Button";
import ButtonGroup from "@mui/material/ButtonGroup";

export const mycomponent = (props) => {
  const {  children } = props;
  return (
     <ButtonGroup{...props}>
       {React.Children.map(props.children, (child) => {
          return (<>{child}</>) 
      })
     }
     </ButtonGroup> 
  );
};
mycomponent.propTypes = {
 children: PropTypes.node, 
};
mycomponent.defaultProps = {
 children: [],
};