Advertisement
varun1729

Untitled

Apr 24th, 2023
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. import React from "react";
  2.  
  3. export default class MyState extends React.Component {
  4. constructor() {
  5. super();
  6. this.state = {
  7. data: "Data from db",
  8. version: 18.2,
  9. flag: true,
  10. subs: ["ML", "Maths", "AI", "UI"],
  11. obj: {
  12. fe: "React JS",
  13. be: "node js",
  14. db: "MongoDb",
  15. },
  16. products: [
  17. { p_id: 111, p_name: "p_one", p_cost: 10000 },
  18. { p_id: 222, p_name: "p_two", p_cost: 20000 },
  19. { p_id: 333, p_name: "p_three", p_cost: 30000 },
  20. { p_id: 444, p_name: "p_four", p_cost: 40000 },
  21. { p_id: 555, p_name: "p_five", p_cost: 50000 },
  22. ],
  23. };
  24. }
  25. render() {
  26. return (
  27. <div>
  28. <h1>Welcome</h1>
  29. <h2 style={{ color: "green" }}>{this.state.data}</h2>
  30. <h2 style={{ color: "red" }}>{this.state.version}</h2>
  31. <h2 style={{ color: "red" }}>{String(this.state.flag)}</h2>
  32. <h2 style={{ color: "red" }}>{this.state.subs}</h2>
  33. <h2 style={{ color: "red" }}>{JSON.stringify(this.state.obj)}</h2>
  34. <table className="table table-sm table-dark table-striped table-hover table-bordered w-50 mx auto">
  35. <thead>
  36. <tr>
  37. <th>S.no</th>
  38. <th>p_id</th>
  39. <th>p_name</th>
  40. <th>p_cost</th>
  41. </tr>
  42. </thead>
  43. <tbody>
  44. {this.state.products.map((e, i) => (
  45. <tr>
  46. <td>{i + 1}</td>
  47. <td>{e.p_id}</td>
  48. <td>{e.p_name}</td>
  49. <td>{e.p_cost}</td>
  50. </tr>
  51. ))}
  52. </tbody>
  53. </table>
  54. </div>
  55. );
  56. }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement