Advertisement
shadiff

benefits2.jsx

Sep 14th, 2023
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. import React, { useState } from 'react';
  2.  
  3. const Benefits = () => {
  4. const [selectedCategory, setSelectedCategory] = useState(null);
  5.  
  6. const handleCategoryClick = (category) => {
  7. setSelectedCategory(category);
  8. // Implement logic to update eligible dependents based on the selected category here.
  9. };
  10.  
  11. // Define a mapping of categories to eligible dependents.
  12. const categoryDependents = {
  13. 'Category A': [2, 4, 6, 8],
  14. 'Category B': [1, 5, 7, 9],
  15. 'Category C': [10, 12, 34, 56],
  16. };
  17.  
  18. return (
  19. <>
  20. <div className='categories-table'>
  21. <table>
  22. <thead>
  23. <tr>
  24. <th>Categories</th>
  25. </tr>
  26. </thead>
  27.  
  28. <tbody>
  29. <tr style={{ cursor: 'pointer' }} onClick={() => handleCategoryClick('Category A')}>
  30. <td>Category A</td>
  31. </tr>
  32.  
  33. <tr style={{ cursor: 'pointer' }} onClick={() => handleCategoryClick('Category B')}>
  34. <td>Category B</td>
  35. </tr>
  36.  
  37. <tr style={{ cursor: 'pointer' }} onClick={() => handleCategoryClick('Category C')}>
  38. <td>Category C</td>
  39. </tr>
  40. </tbody>
  41. </table>
  42.  
  43. {/* End of Table 1 */}
  44. <table>
  45. <thead>
  46. <tr>
  47. <th>Category Benefits</th>
  48. <th>Eligible Dependents</th>
  49. </tr>
  50. </thead>
  51.  
  52. <tbody>
  53. {selectedCategory && categoryDependents[selectedCategory].map((dependents, index) => (
  54. <tr key={index}>
  55. <td>{`Benefit ${index + 1}`}</td>
  56. <td>{dependents}</td>
  57. </tr>
  58. ))}
  59. </tbody>
  60. </table>
  61. </div>
  62. {/* End of Table 2 */}
  63. </>
  64. );
  65. };
  66.  
  67. export default Benefits;
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement