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

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable