Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

How to pass props to a child component in React

Educative Answers Team

A prop can be thought of as a parameter ​in that it changes the behavior (or output) of a component. Props can be passed to any component as they are declared for any HTML tag.

svg viewer

These props can be accessed in any component’s class using the syntax below:

this.props.MyProp

Code

In the code below, we have passed a prop name and location from the parent to the child.

import React from 'react';
require('./style.css');

import ReactDOM from 'react-dom';
import App from './app.js';


RELATED TAGS

Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring