1. Home
  2. Training Library
  3. Thinking in React: Static Versions

Prop Types

Developed with
QA

Contents

keyboard_tab

The course is part of this learning path

Application and Service Development with ReactJS
course-steps 9 certification 5 lab-steps 3
play-arrow
Start course
Overview
DifficultyBeginner
Duration14m
Students10

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

- If we are making components that are to be re-used, perhaps across several applications and by several different developers, it's useful if it's clear what a component should receive as props. The PropTypes package, which needs to be imported into any component that wants to use proptypes, supplies this functionality. It helps ensure the correct usage of components by clearly defining what data type a prop should be, and can be even more explicit by specifying the shape of an object passed as a prop. You can see in the code, after adding the import, we specify proptypes for each props in this component. This is done by adding a prop types object to the component, and then specifying the name of the prop and the proptype it should be. So for header text, this is a proptype.string. For the object prop, we have specified its shape and you can see that for the function prop, we are able to specify it's prop type as func. Console warnings are produced if the correct type for a prop was not used, as you can see from the first warning on the browser window. Proptypes can also be used to express if a particular prop has to be supplied or not. We can chain the, dot is required to any prop type declaration, like has been done for the unsupplied proptype of any. This has the effect of producing a console warning if the prop is not available and you can see this in the second warning, in the console window. Overall, proptypes can make components easier to read and understand. Some argue that, used correctly, proptypes can negate the need for typescript when writing React applications. If you start your project using create-react-app, the proptypes package is included in the project by default so you don't need to download and install it. However, it will only be bundled into your deployment app if you actually use it. If you didn't use create-react-app to start your project, proptypes is an MPM package that can be easily added. More detailed information on proptypes can be found in the official React documentation. So now you have all the knowledge you need to be able to create a fully static version of a application.

About the Author

Students627
Labs8
Courses10
Learning paths3

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.