JS-React: Passing Data Between MyApp and Navbar Components

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: #eee
  display: inline-block

a
  color: white
p
  margin-top: 1em
  text-align: center
  color: #aaa


JAVASCRIPT(babel)/*Reactjs codes in here.*/
class MyApp extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      name: "Ordinary Student",
      property: "Student"
    };
  }
  render() {
    return (
      <div>
        <Navbar property={this.state.property} />
      </div>
    );
  }
}

class Navbar extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    return (
      <div>
        <h1>Properties {this.props.property}</h1>
      </div>
    );
  }
}

/*final code*/
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