How to learn react logo

These tutorials will give you a deeper understanding of React.js. Learn with examples from the Javascript UI library, covering the basics and the advanced.

Browse by tag:

Passing multiple props

Props

Understanding the prop system in React is crucial. Passing multiple props from a parent component down to a child component follows the same logic as passing a single prop.

import React from 'react';
import UserProfile from './UserProfile';

const App = () => {
    return (
        <div className="profiles">
            <UserProfile 
                name="Tina" 
                location="Tampa, FL" 
                photo={someImage.png} 
            />
            <UserProfile 
                name="John" 
                location="San Diego, CA" 
                photo={someImage.png} 
            />
            <UserProfile 
                author="Andy" 
                location="Seattle, WA" 
                photo={someImage.png} 
            />
        </div>
    );
};

For every prop passed down, the props object in the child component will contain a key value pair. In this case the keys will be photo, name and location. They can be referenced using props.photo, props.name and props.location.

import React from 'react';

const UserProfile = (props) => {
    console.log("props", props)
    return (
        <div className="profile">
                <img src={props.photo} className="photo" alt="profile photo" />
            <div className="info">
                <div className="name">
                    {props.name}
                </div>
                <div className="location">{props.location}</div>
            </div>
        </div>
    )
}

export default UserProfile;

How To Learn React is designed and developed by me, Blake Fletcher. It is a project intended to share the things I learn while working with the UI library. As I build things, complete tutorials, read blog posts, and watch videos, I'll add to the site. I hope to eventually bring on other contributors. If interested, send me an email at blkfltchr@gmail.com.