react pass props to component code example
Example 1: route pass props to component
<Route
path='/dashboard'
render={(props) => (
<Dashboard {...props} isAuthed={true} />
)}
/>
Example 2: pass props in react
const expression = 'Happy';
<Greeting statement='Hello' expression={expression}/>
class Greeting extends Component {
render() {
return <h1>{this.props.statement} I am feeling {this.props.expression} today!</h1>;
}
}
Example 3: class component params in react
<input
type= "text"
value={ this.state.value || "" }
placeholder="Enter Name"
/>
Example 4: pass component as props react
const Label = props => <span>{props.children}</span>
const Button = props => {
const Inner = props.inner;
return <button><Inner>Foo</Inner></button>
}
const Page = () => <Button inner={Label}/>
Example 5: pass props
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}