Accepted answer

you may treat the checkbox as a dumb component, which means that it doesn't hold any internal states, but only receives data from outside via props and then render them. you can see the detailed definition of dumb components here.

meanwhile, when the checkbox is clicked, such event will be handled by the component's parent, or event ancestors, this is called inverse data flow, which is described in facebook's thinking in react blog post.

moreover, to decide which component should hold certain states, i find the following guidelines very useful:

remember: react is all about one-way data flow down the component hierarchy. it may not be immediately clear which component should own what state. this is often the most challenging part for newcomers to understand, so follow these steps to figure it out:

for each piece of state in your application:

  • identify every component that renders something based on that state.
  • find a common owner component (a single component above all the components that need the state in the hierarchy).
  • either the common owner or another component higher up in the hierarchy should own the state.
  • if you can't find a component where it makes sense to own the state, create a new component simply for holding the state and add it somewhere in the hierarchy above the common owner component.

the pseudo-code snippet:

const checkbox = react.createclass({
  // propagate the event to parents
  onclick(evt) {
    if (this.props.handleclick) {

  render() {
    return (
      this.props.checked ? 
        <input onclick={this.onclick} type="checkbox" label="checkbox" checked></input> : 
        <input onclick={this.onclick} type="checkbox" label="checkbox"></input>

const container = react.createclass({
  handleclick(evt) {
    // change the container's state, which eventually changes the checkbox's view via props.
    this.setstate({checked: evt.checked});

  render() {
    return (
      <div><checkbox checked={this.state.checked} handleclick={this.handleclick}></checkbox></div>


you change it from only the parent.

class parentcomponent extends react.component{
     childchecked: !this.state.childchecked
      <childcomponent checked={this.state.childchecked} handlecheck={this.handlechildcheck.bind(this)} />

now if you wish to control the checked state from the <childcomponent/> just call this.props.handlecheck() from the <childcomponent/>

this way the controls will always be available within the <childcomponent/> via this.props.handlecheck() within the <parentcomponent/> via this.handlechildcheck().

Related Query

More Query from same tag