0
Q:

how to use props in functional component in react

class Welcome extends React.Component {
  render() {
    return <h1>Bonjour, {this.props.name}</h1>;
  }
}
-1
import React, { useState } from 'react';
import './App.css';
import Todo from './components/Todo'



function App() {
    const [todos, setTodos] = useState([
        {
          id: 1,
          title: 'This is first list'
        },
        {
          id: 2,
          title: 'This is second list'
        },
        {
          id: 3,
          title: 'This is third list'
        },
    ]);

return (
        <div className="App">
            <h1></h1>
            <Todo todos={todos}/> //This is how i'm passing props in parent component
        </div>
    );
}

export default App;
0
function MyApp() {
  return (
    <div>
      <ul>
        <li>Name </li>
        <li>Place </li>
        <li>Animal </li>
      </ul>
    </div>
  )
}

ReactDOM.render(
  <MyApp />,
  document.getElementById('root')
);
0

New to Communities?

Join the community