Prop Types
Start course

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. 


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


If we are making components that are to be reused, perhaps across several applications and by several different developers. It's useful if it's clear what a component you should receive as props. The prop types package which needs to be imported into any component that wants to use prototypes, supplies this functionality. That helps ensure the correct usage of components by clearly defining what data type of prop should be and could 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 prop types 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 prop type it should be. 

So for head attacks, this is a prop type.string, for the object prop, we have specified its shape, and you can see that for the function prop, we are able to specify its prop type as funk. 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. Prop types 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 on supplied prop type 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 prop types can make components easier to read and understand, some argue that used correctly prop types can negate the need for TypeScript when writing applications if you start your project using create react up, the prop types 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 prop types is a npm package that can be easily added. More detailed information on prop types can be found in your official react documentation. So now you have all the knowledge you need to be able to create a fully static version of an application.


About the Author
Learning Paths

Ed is an Outstanding Trainer in Software Development, with a passion for technology and its uses and holding more than 10 years’ experience.

Previous roles have included being a Delivery Manager, Trainer, ICT teacher, and Head of Department. Ed continues to develop existing and new courses, primarily in web design using: PHP, JavaScript, HTML, CSS, SQL, and OOP (Java), Programming Foundations (Python), and DevOps (Git, CI/CD, etc). Ed describes himself as practically minded, a quick learner, and a problem solver who pays great attention to detail. 

Ed’s specialist area is training in Emerging Technologies, within Web Development. Ed mainly delivers courses in JavaScript covering vanilla JS, ES2015+, TypeScript, Angular, and React (the latter is authored by Ed) and has delivered on behalf of Google for PWAs. Ed has also developed a new suite of PHP courses and has extensive experience with HTML/CSS and MySQL. 

Ed is responsible for delivering QA’s Programming Foundations course using the Eclipse IDE. His skillset extends into the DevOps sphere, where he is able to deliver courses based around Agile/Scrum practices, version control, and CI/CD.

Covered Topics