render method in functional component code example

Example 1: functional component react

function Welcome(props) {
  return 

Hello, {props.name}

; } function App() { return (
); } ReactDOM.render( , document.getElementById('root') );

Example 2: react functional components

const component = () => {
console.log("This is a functional Component");
}

Example 3: defining functions in react

export default class Archive extends React.Component { 

    saySomething(something) {
        console.log(something);
    }

    handleClick(e) {
        this.saySomething("element clicked");
    }

    componentDidMount() {
        this.saySomething("component did mount");
    }

    render() {
        return 

Example 4: props in react app

/* PASSING THE PROPS to the 'Greeting' component */
const expression = 'Happy';
 // 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 

{this.props.statement} I am feeling {this.props.expression} today!

; } } -------------------------------------------- function Welcome(props) { return

Hello, {props.name}

; } const element = ; ReactDOM.render( element, document.getElementById('root') );

Example 5: pass props in react

/* PASSING THE PROPS to the 'Greeting' component */
const expression = 'Happy';
 // 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 

{this.props.statement} I am feeling {this.props.expression} today!

; } }

Tags:

Misc Example