Type a Radio Button Component in React using TypeScript

Share this video with your friends

Send Tweet

Our Radiocomponent file contains several compound components to create a related group of radio inputs. The RadioGroupContext is receiving a type of any currently.

This is a great example to peer into how Strict mode works. To see the difference between the strict mode's true and false setting, we will set strict to true. This will change our RadioGroupContext to be of type null which will raise some issues later down the line where trying to destructure an object that might be null.

This also gives us the opportunity to better our application with error handling. I will write out a couple of custom hooks to help out with that.

~ a year ago

You lost type for a children prop in <RadioGroupProps> and <RadioProps>