Simplest checkbox in React.js

Maxim Kehayov
1 min readJun 8, 2020

Need a checkbox component and you need it now? It very much depends on setup, but here is the basic version you could start with.

Create you Checkbox.js file.

Since the components is stateless, your basic needs are covered with:

  • checked prop
  • onChange handler
  • styles

Controlling the state is handled from the parent, but regardless of how you choose to style your component (css modules/css-in-JS, global styles) you will need some CSS to do the trick.

Since error handling is environment specific, I have skipped it, but you should not! :)

Hope this helps someone! Cheers!

PS: If you need a Vue example, you can find it here.

--

--