Skip to content

Instantly share code, notes, and snippets.

@EduardoAC
Last active March 29, 2025 15:39
Show Gist options
  • Save EduardoAC/f18633ff5f0a77bac4c6642a48d4e520 to your computer and use it in GitHub Desktop.
Save EduardoAC/f18633ff5f0a77bac4c6642a48d4e520 to your computer and use it in GitHub Desktop.
Using Render Props - To explicitly define how the label is rendered, we can provide a render function as a prop
export function RadioButtonGroup({ optionList, renderLabel }: RadioButtonGroupProps) {
return (
<div className="radio-button-group">
{optionList.map((option) => (
<div
key={option.value}
disabled={option.disabled}
className={selected === type.value && 'option--active' || ''}
>
{option.icon && <span className={`icon-${option.icon}`} />}
{renderLabel ? renderLabel(option.label) : option.label}
</div>
))}
</div>
);
};
// Usage in Parent Component
<RadioButtonGroup
optionList={suggestDepositAmounts}
renderLabel={(label) => <CustomElement labelText={label} />}
/>;
const suggestDepositAmounts = [
{
value: "100",
label: "100 RSD",
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment