Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="app"></div>
              
            
!

CSS

              
                
              
            
!

JS

              
                class App extends React.Component{
    constructor(props){
      super(props);
      this.state={
        input:'this is the input for now'
      }
   this.handleInput=this.handleInput.bind(this);   
    }
  
    handleInput(x){
      this.setState({
        input:x
      });
      
    }
  
  render(){
    return(
      <div>
        <h1>Passing props from Child to Parent Component</h1>
        <Child getInput={this.handleInput} />
        here's the input: {this.state.input}
        </div>
    );
  }
 }

class Child extends React.Component{
  constructor(){
    super();
    this.state={
      text:''
        }
    this.passingProps=this.passingProps.bind(this);
    }
  passingProps(e){
    var newInput=e.target.value;
    //alert(newInput);
    /*
   this.setState({
     text:newInput
    });
    this.props.getInput(newInput));
    */
 //setSTate is asynchronous and we cant expect setState in one line and get it's value in the next line
//because most probably it hasnt been set yet.
// that is why we are using this.props.getInput(newInput) instead of using this.props.getInput(this.state.text) 
// because the state of text is still not set.
    
//instead we can also use the callback function of setstate to call the parent function
//and then we can use this.state.text
// see how it's done below:
    
    this.setState({
      text:newInput
    },()=>this.props.getInput(this.state.text));
    
  }
  
  render(){
    return(
      <div>
      <input type="text" placeholder="please input a name..." onChange={this.passingProps} />
        
        </div>
    
    )
  }
}

ReactDOM.render(
  <App/>,
  document.getElementById('app')
);
              
            
!
999px

Console