Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is a "Prop" in React?

I just started using React native on iOS to see how it feels like and I have a silly question.. I see everyone talking about "Props", whenever I read an article or a tutorial, the author uses this term a lot and it's the same in the code. For instance, in class declarations I often see constructors like :

class MyClass extends Component {

    constructor(props) {
        super(props);
        this.state = { message: '' };
    }
}

I can't find a clear explanation of what a prop is, could anyone enlighten me about that ?

like image 681
Randy Avatar asked Apr 05 '16 11:04

Randy


People also ask

What is prop in React?

Props are arguments passed into React components. Props are passed to components via HTML attributes. props stands for properties.

What is prop used for?

A prop, formally known as (theatrical) property, is an object used on stage or screen by actors during a performance or screen production. In practical terms, a prop is considered to be anything movable or portable on a stage or a set, distinct from the actors, scenery, costumes, and electrical equipment.

What is props and state in React?

While both hold information that influences the output of render, they are different in one important way: props get passed to the component (similar to function parameters) whereas state is managed within the component (similar to variables declared within a function).

What is props in JS?

Props stand for "Properties." They are read-only components. It is an object which stores the value of attributes of a tag and work similar to the HTML attributes. It gives a way to pass data from one component to other components.


1 Answers

props are the values that you pass down to your React component. So whenever you have a component you'll see something like this:

<MyComponent value1={value1} isTrue={true} />
like image 67
Keith Rousseau Avatar answered Sep 29 '22 10:09

Keith Rousseau