react get props in functional component code example

Example 1: function component with props

import React from "react"

function Checkbox(props){
    return (
        <div>
            <input type="checkbox" />
            <label>{props.value}</label>
        </div>
    )
}

export default Checkbox

Example 2: functional component 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')
);

Example 3: functional components react

function Comment(props) {
  return (
    <div className="Comment">
      <div className="UserInfo">
        <img className="Avatar"
          src={props.author.avatarUrl}
          alt={props.author.name}
        />
        <div className="UserInfo-name">
          {props.author.name}
        </div>
      </div>
      <div className="Comment-text">
        {props.text}
      </div>
      <div className="Comment-date">
        {formatDate(props.date)}
      </div>
    </div>
  );
}

Example 4: How to acces props of a functional component

const Child = (props) => {  return (    <div style={{backgroundColor: props.eyeColor}} />  )}