T
T
testtoster2020-01-30 09:10:31
JavaScript
testtoster, 2020-01-30 09:10:31

How to pass a component as a prop?

There is a task. Create an App2.js component and include it in App.js. Pass s3 (located in App) as a prop z1 inside App2. Display it on the page in App2 as props.

I can't figure out how to pass information from one component to another. Thanks everyone for the replies

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2020-01-30
@testtoster

app.js:

import React from "react";
import ReactDOM from "react-dom";

import App2 from "./App2";

const App = () => {
  const s3 = "foo";
  return <App2 z1={s3} />;
};

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

App2.js:
import React from "react";

const App2 = ({ z1 }) => {
  return <div>{z1}</div>;
};

export default App2;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question