how to pass value to props in react code example

Example 1: how to pass state variable in swiftui

// View1:

struct FirstView: View {
    @State var count = 0
    var body: some View {
        VStack{
            Text("\(self.count)")
            Button(action:
                {self.count = self.count-10})
            {
                Text("-")
            }
            SecondView(count: self.$count)
        }
    }
}

// And View2:

struct SecondView: View {
    @Binding var count: Int
    var body: some View {
        Button(action: {self.count = 0}) {
            Text("Reset")
        }
    }
}

Example 2: pass props in react

/* PASSING THE PROPS to the 'Greeting' component */
const expression = 'Happy';
 // statement and expression are the props (ie. arguments) we are passing to Greeting component

/* USING THE PROPS in the child component */
class Greeting extends Component {
  render() {
    return 

{this.props.statement} I am feeling {this.props.expression} today!

; } }

Tags:

Misc Example