Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save EduardoAC/3e0250e6e464274a5dae42b087815c6f to your computer and use it in GitHub Desktop.
Save EduardoAC/3e0250e6e464274a5dae42b087815c6f to your computer and use it in GitHub Desktop.
Using Higher-Order Components (HOCs) - A more advanced pattern in React is to wrap the RadioButtonGroup with an HOC that injects label customization logic
export function withCustomLabel(Component: ReactNode) {
return (props) => {
const modifiedOptions = props.optionList.map((option) => ({
...option,
label: <CustomElement labelText={option.label} />,
}));
return <Component {...props} optionList={modifiedOptions} />;
};
};
const EnhancedRadioButtonGroup = withCustomLabel(RadioButtonGroup);
// Usage
<EnhancedRadioButtonGroup optionList={suggestDepositAmounts} />;
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