Advertisement
karlakmkj

React (JSX) - pass props from component to component

Jan 28th, 2021
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2.  
  3. export class Greeting extends React.Component { //export component class for App class
  4.   render() {
  5.     return <h1>Hi there, {this.props.name}!</h1>; //then this line will appear with the Greeting instance in App class
  6.   }
  7. }
  8.  
  9. ====================================================================================
  10. import React from 'react';
  11. import ReactDOM from 'react-dom';
  12. import {Greeting} from './Greeting'; //import Greeting component class
  13.  
  14. class App extends React.Component {
  15.   render() {
  16.     return (
  17.       <div>
  18.         <h1>
  19.           Hullo and, "Welcome to The Newzz," "On Line!"
  20.         </h1>
  21.         <Greeting name="Orange"/> //add a Greeting instance with a name attribute
  22.         <article>
  23.           Latest newzz:  where is my phone?
  24.         </article>
  25.       </div>
  26.     );
  27.   }
  28. }
  29.  
  30. ReactDOM.render(
  31.   <App />,
  32.   document.getElementById('app')
  33. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement