0

Here is a TableCell which is inside array.map((row,index) =>{})

 <TableCell component="th" scope="row" padding="none">
      {row.createdAt}
 </TableCell>

I want to pass this {row.createdAt} as a parameter in a function and instead of printing {row.createdAt} inside this I want to print the value returning from the function. Please tell me how to do that??

3 Answers3

0

You can call a function within the bracket which are inside your TableCell Component

<TableCell component="th" scope="row" padding="none">
   {yourFunction(row.createdAt)}
 </TableCell>

You call a function in JSX by calling it within {}

Yves Kipondo
  • 5,289
  • 1
  • 18
  • 31
0

It's pretty simple, just call that function and pass the row.createdAt

 <TableCell component="th" scope="row" padding="none">
      {this.yourFunctioName(row.createdAt)} // if class based component
      // OR {yourFunctioName(row.createdAt)}   if function based component
 </TableCell>
Surjeet Bhadauriya
  • 6,755
  • 3
  • 34
  • 52
0

Just create a function then call it then pass the row.createdAt as a parameter

       function getCreatedAt(createdAt) {
          // Do something
          // HERE
       
          return createdAt
       }

       <TableCell component="th" scope="row" padding="none">
            {getCreatedAt(row.createdAt)} 
       </TableCell>
Abu Dujana Mahalail
  • 1,547
  • 1
  • 8
  • 21