SHARE
TWEET

Untitled

a guest Feb 17th, 2020 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import {useState, useEffect} from 'react';
  3.  
  4. const ViewBuilding = (props) => {
  5.     //const [selectedBuilding, setSelectedBuilding] = useState(0);
  6.    
  7.     const selectedBuilding = (id) => {
  8.         props.selectedBuilding(id);
  9.     };
  10.  
  11.         const buildDescr = (building) => {
  12.             console.log(building)
  13.             if (!building) {
  14.                 return (
  15.                     <>
  16.                         {' '}
  17.                         <i>Click on a name to view more information</i>
  18.                     </>
  19.                 );
  20.             }
  21.             return (
  22.                 <>
  23.                     <b>Code: </b> {building.code}
  24.                     <br/>
  25.                     <b>Name: </b> {building.name}
  26.                     <br/>
  27.                     <b>Address: </b> {building.address}
  28.                     <br/>
  29.                     <b>Coordinates: </b> {building.coordinates && `${building.coordinates.latitude}, ${building.coordinates.longitude}`}
  30.                 </>
  31.             )
  32.         }
  33.  
  34.         return (
  35.             <div>
  36.                 <p>
  37.                     {/* {buildDescr(data.find((building) => building.id === selectedBuilding))} */}
  38.                     {/* {props.data.map(directory => {buildDescr(directory.id === selectedBuilding))}} */}
  39.                     {/* props.data.map(directory => {    
  40.                         {
  41.                             return (
  42.                                 buildDescr(directory);
  43.                             );
  44.                         }
  45.                     }); */}
  46.                     {/* {buildDescr(data.find(b => b.id === selectedBuilding(b.target.value)))} */}
  47.                     {buildDescr(props.data.find(b => b.id === selectedBuilding))}
  48.                    
  49.                 </p>
  50.             </div>
  51.         );
  52.     }
  53. export default ViewBuilding;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top