destructuring in react js code example
Example 1: definition destructuring react
const Attraction = ({ auth, attraction }) => { return ( <div auth={auth} key={attraction.id}> <Link token={auth.token} to={`/attractions/${attraction.url_name}`} key={attraction.id} > <img alt={attraction.name} src={attraction.image_url} /> <h1>{attraction.name}</h1> </Link> <StarRatings rating={attraction.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> ); }}