Created
October 11, 2021 11:34
-
-
Save yarigpopov/510c09febbdca7b3292795fce3547773 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
function App() { | |
const [value, setValue] = React.useState(null); | |
const onChange = (value: string): void => { | |
setValue(value); | |
}; | |
return ( | |
<div className="container App"> | |
<Banner | |
title={'React Component Patterns'} | |
subtitle={'Compound Components'} | |
/> | |
<div> | |
<h1 className="my-5">Parent Value: {value}</h1> | |
{/* The parent component that handles the onChange events | |
and managing the state of the currently selected value. */} | |
<RadioImageForm onStateChange={onChange}> | |
{/* The child, sub-components. | |
Each sub-component is an radio input displayed as an image | |
where the user is able to click an image to select a value. */} | |
{DATA.map( | |
({ label, value, imgSrc }): React.ReactElement => ( | |
<RadioImageForm.RadioInput | |
label={label} | |
value={value} | |
name={label} | |
imgSrc={imgSrc} | |
key={imgSrc} | |
/> | |
), | |
)} | |
</RadioImageForm> | |
</div> | |
</div> | |
); | |
} | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment