E
E
Elena2021-12-10 12:28:17
React
Elena, 2021-12-10 12:28:17

How to call a component in a stateless function?

function App() {
  <Component></Component>
}

// Component.js
function Component(props) {
  return (<h1>{props.name}</h1>)
}

// Main.js
function Main() {
  const add = () => {
   // Здесь нужно вызвать Component
   return (<Component name="Имя"></Component>)
  }
}

I need to add a prop when calling a component, but React doesn't see it anyway. Maybe I'm calling it wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
y0u, 2021-12-10
@y0u

function Component(props) {
  return (<h1>{props.name}</h1>)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question