Passing regular values as props

Passing regular values as props

I found myself looking how to do this in my first days developing some code with React

You can also grab data from a component’s state and pass it down as props for any of their child components.

class ParentComponent extends React.Component {
  constructor(props) {
    super(props);
    this.isLoading = {true};
  }
  render() {
    return <SomeChildComponent disabled={this.state.isLoading} />;
  }
}

The value for that part comes from that component’s props. Continuing with the example code above, this is how the child component might use the data received from the parent’s state:


class ChildComponent extends React.Component {
  render() {
    return <p>is it loading? {this.props.disabled}.</p>;
  }
}