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
5
lab-steps
3
play-arrow
Start course
Overview
DifficultyBeginner
Duration14m
Students27

Description

This module looks at more complex data structures, building on what was covered in the intermediate data structures module.

Learning Objectives 

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

  • How to construct a factor in R  
  • How to construct a data frame in R  
  • How to modify a data frame  
  • How to subset a data frame
  • Data frames automatically factorising data in R  

Intended Audience 

Aimed at all who wish to learn the R programming language. 

Prerequisites 

No prior knowledge of R is assumed.

Delegates should already be familiar with basic programming concepts such as variables, scope, and functions.

Experience of another scripting language such as Python or Perl would be an advantage.

Understanding mathematical concepts will be beneficial.

Feedback 

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

Transcript

- [Narrator] 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.

About the Author

Students1293
Labs8
Courses29
Learning paths5

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