react class component destructure props code example

Example 1: definition destructuring react

const Attraction = ({  auth,   auth: { token },  attraction: { id, url_name, name, image_url, average_rating }}) => {  return (    <div auth={auth} key={id}>      <Link token={token} to={`/attractions/${url_name}`} key={id}>        <img alt={name} src={image_url} />        <h1>{name}</h1>      </Link>      <StarRatings rating={average_rating} />    </div>  );};

Example 2: definition destructuring react

class Attraction extends React.Component {  render() {    const {      auth,      auth: { token },      attraction: { id, url_name, name, image_url, average_rating }    } = this.props;return (      <div auth={auth} key={id}>        <Link token={token} to={`/attractions/${url_name}`} key={id}>          <img alt={name} src={image_url} />          <h1>{name}</h1>        </Link>        <StarRatings rating={average_rating} />      </div>    );  }}

Example 3: definition destructuring react

const Attraction = props => {  return (    <div auth={props.auth} key={props.attraction.id}>      <Link        auth={props.auth.token}        to={`/attractions/${props.attraction.url_name}`}        key={props.attraction.id}      >        <img           alt={props.attraction.name}           src={props.attraction.image_url}         />        <h1>{props.attraction.name}</h1>      </Link>      <StarRatings rating={props.attraction.average_rating} />    </div>  );};