Skip to content

Instantly share code, notes, and snippets.

@jmacqueen
Last active July 21, 2021 11:56
Show Gist options
  • Save jmacqueen/3e65af4feba52ef3ddff56f7e470d546 to your computer and use it in GitHub Desktop.
Save jmacqueen/3e65af4feba52ef3ddff56f7e470d546 to your computer and use it in GitHub Desktop.
React Exercise

The Task

Implement a React component that will receive an array of options:

  [
    { label: 'Label 1', value: 1 },
    { label: 'Label 2', value: 2 },
    { label: 'Label 3', value: 3 },
    { label: 'Label 4', value: 4 }
  ]

And then render a set of radio buttons with the corresponding labels and values. Changing the radio button selection should update a value in a second, containing component's state and display that value on the page.

I expect at least two components in the final exercise, RadioGroup and Parent. I'm most interested in how information is passed into and out of the RadioGroup component. We are working primarily with functional components these days, but feel free to use class-based components if you are more comfortable with them.

A repo based off of create-react-app would be ideal, but I'll also accept an online tool like CodeSandbox or Codepen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment