props and state react code example

Example 1: state and props

What is the Props
Props is short for properties and they are used to pass data between React components. React’s data flow between components is uni-directional
wt is State
which allows components to create and manage their own data

Example 2: props and state react

function tick() {
  const element = (
    <div>
      <h1>Hello, world!</h1>
      <h2>It is {new Date().toLocaleTimeString()}.</h2>
    </div>
  );
  ReactDOM.render(    element,    document.getElementById('root')  );}

setInterval(tick, 1000);

Example 3: diagram how props are passed in react

import React, { Component } from 'react'; class App extends Component {  render() {    const greeting = 'Welcome to React';     return (      <div>        <Greeting greeting={greeting} />      </div>    );  }} class Greeting extends Component {  render() {    return <h1>{this.props.greeting}</h1>;  }} export default App;