0
Q:

react pass props hooks

/* 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>;
  }
}
7
import React, { useState } from 'react';

class WelcomeName extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}</h1>
  }
}

function HighHookWelcome() {
  const [name ,setName] = useState("Default Name Here");
  return(
    <WelcomeName
      name={name}
    />
  );
}

// Note: Didn't need to use state for a static value.
// Minimal example, just to illustrate passing state/props.
// setName is a function to change the name value.
-1

New to Communities?

Join the community