Skip to content

Commit

Permalink
Merge pull request Techtonica#2047 from Techtonica/quizzes
Browse files Browse the repository at this point in the history
Adding Answer Keys
  • Loading branch information
Yosolita1978 authored Nov 28, 2023
2 parents 94cfed9 + abb5a6c commit 81e0250
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions react-js/quizzes/answerkeys/passingprops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#### Answer Key for Quiz about Passing Props.

The code is working correctly, so you don't need to fix anything - all the solutions should be only comments in the code.

Please remember that a comment star with `\\`

1. Write a comment in the code sending props from the form component to its parent component. Your comment should explain why the process is important, and please add a "Don't delete" note.

**Answer:** The function `onSendData` is being passed to the Form component as props. Inside the component Form (`form.jsx`), we can find the function in two different moments:
Line 3, being deconstructed inside the object props
Line 11, being called inside the function `handleSendData`

The process is important because the parent component (`app.jsx`) is the one that sends the function as props to the Form. That guarantees that the parent component maintains control of the data.

For rating purposes, the participant should have at least a comment on the function `handleSendData` inside the Form Component that specifies that the function `onSendData` is being passed as props.

2. Write a comment in the code sending props from the parent component to the child component called message.jsx. You should explain in your comment why the process is important, and please add a note for not deleting it.

**Answer:** The Message component (`message.jsx file`) receives the email propos. You can find it on line 1 as an object deconstructed and used in line 5 of the component, asking the variable to check if something is not null to be shown to the user.

3. Inside the app.jsx component, include a comment that documents how the app works and how the data moves from one component to another.

**Explanation**

- Form Component (form.jsx): It has an input field and a button. When the button is clicked, it calls the handleSendData function, which then calls the onSendData prop (a function passed from the parent) with the current input value.
- App Component (App.jsx): It renders the child component and provides it with the onSendData prop. This prop is a function (handleReceiveData) that updates the parent's state with the data received from the child.
- Message Component (message.jsx): It renders a child component and provides a simple p tag with the success message for the user if an email has been received.

This setup allows the child component to send data back to the parent component. The parent component can then use or display this data as needed in the message component.

0 comments on commit 81e0250

Please sign in to comment.