create react component class
class MyComponent extends React.Component{ constructor(props){ super(props); }; render(){ return( <div> <h1> My First React Component! </h1> </div> ); } };
create react component class
class MyComponent extends React.Component{ constructor(props){ super(props); }; render(){ return( <div> <h1> My First React Component! </h1> </div> ); } };
props in react
function Welcome(props) { return <h1>Hello, {props.name}</h1>; } function App() { return ( <div> <Welcome name="Sara" /> <Welcome name="Cahal" /> <Welcome name="Edite" /> </div> ); } ReactDOM.render( <App />, document.getElementById('root') );
props in class react
class MouseTracker extends React.Component { constructor(props) { super(props); this.handleMouseMove = this.handleMouseMove.bind(this); this.state = { x: 0, y: 0 }; } handleMouseMove(event) { this.setState({ x: event.clientX, y: event.clientY }); } render() { return ( <div style={{ height: '100vh' }} onMouseMove={this.handleMouseMove}> <h1>Move the mouse around!</h1> <p>The current mouse position is ({this.state.x}, {this.state.y})</p> </div> ); } }
props in react app
/* 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>; } } -------------------------------------------- function Welcome(props) { return <h1>Hello, {props.name}</h1>; } const element = <Welcome name="Sara" />; ReactDOM.render( element, document.getElementById('root') );
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>; } }
React js props
function App() { return ( <div className="App"> <NewComponent name="Ariful Islam Adil" profession="Web-Developer"></NewComponent> </div> ); } function NewComponent(props) { return ( <div className="test-class"> <h1>Name: {props.name}</h1> <h3>Profession: {props.profession}</h3> </div> ) } export default App;
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us