JS-React: Pass a Callback as Props

HTML
<div id="app">

  </div>


CSS(sass)


html, body
  height: 100%
  
body
  background: #333
  display: flex
  justify-content: center
  align-items: center
  font-family: Helvetica Neue
  
h1
  font-size: 2em
  color: lightblue
  display: inline-block

input
  color: black,
  font-size: 1.4em
p
  margin-top: 1em
  text-align: center
  color: #aaa,

  font-size: 2em





JAVASCRİPT(babel)/*Reactjs*/

class MyApp extends React.Component { constructor(props) { super(props); this.state = { inputValue: '' } this.handleChange = this.handleChange.bind(this); } handleChange(event) { this.setState({ inputValue: event.target.value }); } render() { return ( <div> <GetInput input= {this.state.inputValue} handleChange={this.handleChange}/> <RenderInput input={this.state.inputValue}/> </div> ); } }; class GetInput extends React.Component { constructor(props) { super(props); } render() { return ( <div> <h1>Get Input:</h1><br /> <input value={this.props.input} onChange={this.props.handleChange} placeholder="write to this line."/> </div> ); } }; class RenderInput extends React.Component { constructor(props) { super(props); } render() { return ( <div> <br /><h1>Input Render:</h1> <p>{this.props.input}</p> </div> ); } }; React.render(<MyApp />, document.getElementById("app"));

Comments

Popular posts from this blog

Tech Duos For Web Development

CIFAR-10 Dataset Classification Using Convolutional Neural Networks (CNNs) With PyTorch

Long-short-term-memory (LSTM) Word Prediction With PyTorch