Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. import React, { Component } from "react";
  2. import fire from '../../fire.js';
  3.  
  4. class pencocokanKornea extends Component {
  5. constructor(){
  6. super();
  7. this.state = {
  8. patient : [],
  9. address : [],
  10. operation : [],
  11. phone : [],
  12. table : ''
  13. };
  14. }
  15. componentDidMount(){
  16. const rootRef = fire.database().ref();
  17. const pasienRef = rootRef.child('pasien');
  18. pasienRef.once('value', snap => {
  19. snap.forEach( row => {
  20. this.setState({
  21. patient: this.state.patient.concat([row.val().name]),
  22. address: this.state.address.concat([row.val().address]),
  23. operation: this.state.operation.concat([row.val().operationType]),
  24. phone: this.state.phone.concat([row.val().phone])
  25. });
  26. });
  27. const tableList = this.state.patient.map((name, index) =>
  28. <tr>
  29. <td>{name}</td>
  30. <td>{this.state.address[index]}</td>
  31. <td>{this.state.operation[index]}</td>
  32. <td>{this.state.phone [index]}</td>
  33. </tr>
  34. );
  35. this.setState({
  36. table : tableList
  37. })
  38. });
  39. };
  40. render() {
  41. return (
  42. <table>
  43. <thead>
  44. <tr>
  45. <th>patient name</th>
  46. <th>address</th>
  47. <th>operation type</th>
  48. <th>phone</th>
  49. </tr>
  50. </thead>
  51. <tbody>{this.state.table}</tbody>
  52. </table>
  53. );
  54. }
  55. }
  56.  
  57. export default pencocokanKornea;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement