1. Home
  2. Training Library
  3. Programming
  4. Courses
  5. Thinking in React: Static Versions

Receiving and Using Props

Developed with
QA

Contents

keyboard_tab

The course is part of this learning path

ReactJS: Zero to Hero
course-steps
14
certification
7
lab-steps
3
description
1
play-arrow
Start course
Overview
DifficultyBeginner
Duration14m
Students138
Ratings
3.4/5
starstarstarstar-halfstar-border

Description

This module looks at static versions in React, Props, and Mock Components to use when testing an application.

Learning Objectives 

The objectives of this module are to provide you with an understanding of: 

  • How to be able to build a static version of an application 
  • How to use Props in components 
  • How to be able to test Component snapshots and Components with props 
  • How to be able to Mock components when testing 

Intended Audience  

This learning path is aimed at all who wish to learn how to use the ReactJS framework.  

Prerequisites of the Course 

It is essential you understand the face of contemporary web development to attend this course. We insist upon JavaScript experience, along with good HTML and CSS skills. 

Feedback 

We welcome all feedback and suggestions - please contact us at qa.elearningadmin@qa.com to let us know what you think. 

Transcript

Now my child component has been pass props how can I use them? For to receive it's props, it has to know about them in its functions arguments. Props are passed as an object, so we have three options here. We can just pass the prop's object as single argument to the RO function light shown here. To use the specific props value inside the component, say "header text," We need to prefix it with the prop stop notation. Here's an example of what I mean. As you can see the application is rendered the value that has been passed from the parent component where I've used prop start header text. The second and third options both use JavaScript object restructuring. The size of the props object may determine which we choose here. It can district to the props object in the argument by passing the arrow function an object with all the prop names supplied to the component. So for our component, this would look like this. The other option is to pass in the props object and then restructuring the component function body. In either case, the advantage of this is that we can simply use the prop name in the component code now, which makes it more readable. Now I can remove the prop stop notation, and achieve the same result. You'll notice that React is given warnings that we've got some unused values. This is common in React and it helps us to minimize the amount of code that gets bundled that isn't used. once I've got these values in the component, I can use them as part of the component logic. These props can now be used as expressions in the return to display data, including calling the function. I can also use values as part of the component logic. Here we show a map functions calculate the next number one we add on to the current number in the summer Ray prop and create an array of JSX expressions to display it in the components return. You'll notice there's a warning here on the console. Each child in English should have a unique key prop. This is because react needs to be able to identify each component it renders. And when we constructed the array. We didn't let react know, which component was which. So to fix this, I would add a key property to each of the JSX expressions. In this instance, I'll use the sequence number, as I do that, it removes the warning. We can also loop through the keys and values in the object prop to create an array of JSX expressions to display these. The logic to create the array is just JavaScript that pushes a JSX expression to an array. So that's how we can receive props inside a component, distribute to them so we can easily use their names and use their values, either in component logic, or as part of a JSX expression to display on our screen.

Lectures

About the Author
Students2869
Labs8
Courses29
Learning paths6

An outstanding trainer in software development with more than 15 years experience as a Corporate and Apprentice Trainer, ICT Teacher and Head of Department, with a passion for technology and its uses. Continuing to develop existing and new skills and courses, primarily in web design using PHP, JavaScript, HTML, CSS and SQL but also OOP (Java), programming foundations (Using Python), DevOps (Git, CI/CD, etc) and Agile/Scrum. Practically minded, a quick learner and a problem solver with an attention to detail to ensure high quality outcomes.

Covered Topics