How To Use Props In A Function Inside A Functional Component In React Code Example


Example 1: function component with props

import React from "react"  function Checkbox(props){     return (         <div>             <input type="checkbox" />             <label>{props.value}</label>         </div>     ) }  export default Checkbox

Example 2: how to use props in functional component in react

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;

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?