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

Default 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
Students173
Ratings
3.5/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

Some components may not need props to be supplied every time they are used, as a default value may be sufficient in many cases. Props are immutable and must be supplied when a component is rendered. So how can we get default values? Default props is the answer. If appropriate, we can supply values for each prop that should be received by the component, ensuring that it will work and render correctly, even if all the values are not supplied by the rendering parent. Here, we have a component that expects to receive header text, content text, and content text 2, as props. We are going to supply header text and content text with default values. To give a component default props, we just need to add a default props object to it. Inside the object, we add keys of all the props that we want to have a default value and then supply a value. You can see from the display in the browser window, that if a prop is not supplied and a default value is available, the default value is used. If a value is supplied, as in the case of header text, the value's supplied by the parent. You can see that if a prop is not supplied and a default value is available, that default value is used. If a value is supplied by the parent, as in the case of header text, then that value is used. Props that are not supplied and do not have a value, will fail silently and say a part of a JSX expression, or if they can be used as a falsy value in a JavaScript expression. Otherwise, normal JavaScript errors will be shown. As we are trying to call a substring function on content text 2 here, which is undefined, we will get an unknown type error, as you can see in the browser console, on the right hand side of the window.

Lectures

About the Author
Students3156
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