1

This is involving javascript using react. The problem is to pass 2 variables of data from...

Question

This is involving javascript using react. The problem is to pass 2 variables of data from...

This is involving javascript using react. The problem is to pass 2 variables of data from a parent component to a child component. Pass these two variables to the child component: user1 = "[email protected]", user2 = "[email protected]".

-----------------Parent.js-----------------

import React from "react";
import ReactDOM from "react-dom";
import GuestApp from "./GuestApp";

class App extends React.Component {

constructor(props) {

super(props); // Must call

this.state = {role: "admin"};

}

render() {

switch (this.state.role) {

case 'guest':

return <GuestApp /* Insert the passing data in here */ />;

break;
}
}
}
ReactDOM.render(<App />, document.getElementById("root"));

-----------------Child.js-----------------
import React from "react";

class GuestApp extends React.Component

{

constructor(props)

{

super(props); // Must call

this.state = {show: "home"};

}
render()
{
/* Insert any code here as needed to accept the passed down information from parent.js */
}
}

Modify the parent and child files as needed to pass down the information from parent to child. Need not worry about any component rendering or anything else. This exercise is only to correctly pass information down.

Answers

We can do this in multiple ways but here I have passed it down as a prop and the used it using object destructuring. My code is below.

This is the parent component

import React from "react";
import ReactDOM from "react-dom";
import GuestApp from "./GuestApp";
class App extends React.Component {
  constructor(props) {
    super(props); // Must call
    this.state = { role: "admin" };
  }
  render() {
    switch (this.state.role) {
      case "guest":
        return (
          <GuestApp
            /* Insert the passing data in here */
            user1={"[email protected]"}
            user2={"[email protected]"}
          />
        );
        break;
    }
  }
}
ReactDOM.render(<App />, document.getElementById("root"));

This is the child component.

import React from "react";
class GuestApp extends React.Component {
  constructor(props) {
    super(props); // Must call
    this.state = { show: "home" };
  }
  render() {
    /* Insert any code here as needed to accept the passed down information from parent.js */
    const { user1, user2 } = this.props;
  }
}

I hope you liked it.


Similar Solved Questions

1 answers
For manufacturers, long-term tangible assets: Select one: a. Are often the largest item on the balance...
For manufacturers, long-term tangible assets: Select one: a. Are often the largest item on the balance sheet b. Are usually the smallest item on the balance sheet c. Are not shown on the statement of financial position d. Are classified as liabilities...
1 answers
PA 11-4 (Statie) Kooyman hardware sells 16 different types of Kooyman hardware sells 16 different types...
PA 11-4 (Statie) Kooyman hardware sells 16 different types of Kooyman hardware sells 16 different types of drills. They had demand for 10 of the drills and satisfied 80 percent of the (Round your answer to 1 decimal place.) What was their fill rate for drills? 86,6%...
1 answers
You have an opportunity to buy a building. You have a tenant lined up that will...
You have an opportunity to buy a building. You have a tenant lined up that will generate $20,254 per year in cash flows for two years. The rent pays at the beginning of each year. At the end of two years, you anticipate selling the building for $248,962. How much would you be willing to pay for the ...
1 answers
Check my Enviro Company issues 700%, 10-year bonds with a par value of $360,000 and semiannual...
Check my Enviro Company issues 700%, 10-year bonds with a par value of $360,000 and semiannual interest payments. On the issue date, the annual market rate for these bonds is 4.00%, which implies a selling price of 126 1/8. The straight-line method is used to allocate interest expense. 1. Using the ...
1 answers
Two important cost methods - variable costing and absorption costing (also called full costing). Because full...
Two important cost methods - variable costing and absorption costing (also called full costing). Because full costing is accepted for financial reporting purposes and variable costing is not, why should we be concerned about the difference between them? What is the difference, and why is it importan...
1 answers
72. What is the most common side effect seen in patients eating foods hih in tytamine...
72. What is the most common side effect seen in patients eating foods hih in tytamine content while on MAOIS. 73. What type of foods should be avoided when taking MAOL 74. Which electrolyte imbalance is seen with lithium carbonate leskalith. 75. What are antidepressents used for. 76. What are anxiol...
1 answers
Why is there no conclusive berefit that Anabolic Steroids and Growth Hormones may have helped baseball...
Why is there no conclusive berefit that Anabolic Steroids and Growth Hormones may have helped baseball players like Bary Bonds, Sammy Sosa, and mark McGuire to build larger, stronger and more powerful musculature that helped them recover from workouts faster?...
1 answers
Question2 Determine the LRFD design De Pn for the axially loaded W12 x 96 column which...
Question2 Determine the LRFD design De Pn for the axially loaded W12 x 96 column which has the bracing and end support conditions as shown (the column is braced on its weak y axis as shown in the figure). Fy 50 ksi. Solve: a) Using Trial and error Procedure; i.e. Table 4-22; b) Using LRFD Tables: i....
1 answers
[10] How 'wide' is a bit on a 2.0-Gbps link? How long is a bit in...
[10] How 'wide' is a bit on a 2.0-Gbps link? How long is a bit in copper wire, where the speed of propagation is 2.3x108 m/s?...
1 answers
2.5 points Save Answer Find the indicated probability. Among the contestants in a competition are 46...
2.5 points Save Answer Find the indicated probability. Among the contestants in a competition are 46 women and 23 men. If 5 winners are randomly selected, what is the probability that they are all men? 0.02455...
1 answers
You are promised one off bonus € 66217 in two years time. If the discount rate...
You are promised one off bonus € 66217 in two years time. If the discount rate is 6% what is the present value of this payment....
1 answers
Please help
A small block of mass m = 1.7 kg slides,without friction, along the loop-the-loop track shown. The blockstarts from the point P adistance h = 58.0 mabove the bottom of the loop of radius R = 19.0 m. What isthe kinetic energy of the mass at the point A on theloop?What is the downward acceleration of ...
1 answers
Update the project charter for the remainder of the project in response to Adams’ memo (lines 241 through 246).
Update the project charter for the remainder of the project in response toAdams’ memo (lines 241 through 246)....
1 answers
Explain the purpose of a medication administration record (MAR) and give an example of how it...
explain the purpose of a medication administration record (MAR) and give an example of how it might be used by a pharmacist in his/her daily practice....
1 answers
Exercise 3-4A (Algo) Determining variable cost from incomplete cost data LO 3-1 Benson Corporation produced 217,000...
Exercise 3-4A (Algo) Determining variable cost from incomplete cost data LO 3-1 Benson Corporation produced 217,000 watches that it sold for $21 each during year 2. The company determined that fixed manufacturing cost per unit was $9 per watch. The company reported a $1,519,000 gross margin on its y...
1 answers
What is the calculated value of the cell potential at 298K for an electrochemical cell with the following reaction, when...
What is the calculated value of the cell potential at 298K for an electrochemical cell with the following reaction, when the Cu2+ concentration is 3.12×10-4 M and the Cr3+ concentration is 1.44 M ? 3Cu2+(aq) + 2Cr(s)3Cu(s) + 2Cr3+(aq) Answer: V The cell reaction as written above is spontaneous...

-- 0.047522--