This module looks at static versions in React, Props, and Mock Components to use when testing an application.
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
This Learning Path is aimed at all who wish to learn how to use the ReactJS framework.
Prerequisites of the Course
We welcome all feedback and suggestions - please contact us at email@example.com to let us know what you think.
Now my trial component has been past propped how can I use them? For a component to receive its props, it has to know about the minutes function arguments. Props are passed as an object. So we have three options here. We can just pass the props object as a single argument to the arrow function like shown here. To use the specific props value inside the component, say header text, we need to prefix it with the props dot notation.
The other option, is to pass in the props object and then de structure in the component function body. In either case, the advantage of this is that we can simply use the prop name and the component code now, which makes it more readable. Now I can remove, the props dot notation, and achieve the same result. You'll notice that React has given warnings that we've got some unused values. This is common in React, and it helps you to minimize the amount of code that it 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 function to calculate the next number when we add one to the current number in the sum array 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 a list 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.
Ed is an Outstanding Trainer in Software Development, with a passion for technology and its uses and holding more than 10 years’ experience.
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.