Answers for "how to pass value to props in react"

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")
        }
    }
}
Posted by: Guest on March-13-2020
7

pass props in react

/* PASSING THE PROPS to the 'Greeting' component */
const expression = 'Happy';
<Greeting statement='Hello' expression={expression}/> // 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 <h1>{this.props.statement} I am feeling {this.props.expression} today!</h1>;
  }
}
Posted by: Guest on May-29-2020

Code answers related to "how to pass value to props in react"

Code answers related to "Swift"

Browse Popular Code Answers by Language