Created
March 21, 2019 15:34
-
-
Save jklapacz/83db77e9bd914b04d61da42d8bb8a491 to your computer and use it in GitHub Desktop.
Table example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useEffect, useState } from 'react'; | |
| import { Button } from '@blueprintjs/core'; | |
| import { Cell, Column, Table } from '@blueprintjs/table'; | |
| import axios from 'axios'; | |
| const cellRenderer = (data: Driver[] | undefined) => (rowIndex: number) => { | |
| if (data && rowIndex) { | |
| console.log('hey', data, rowIndex, data[rowIndex]); | |
| return <Cell>{data[rowIndex]}</Cell>; | |
| } else { | |
| return <Cell>'-'</Cell>; | |
| } | |
| }; | |
| const apiUrl = 'http://localhost:3000'; | |
| function MyTable() { | |
| const [data, setData] = useState<User[]>(); | |
| useEffect(() => { | |
| const fetchData = async () => { | |
| const response = await axios.get<User[]>(`${apiUrl}/users`); | |
| setData(response.data); | |
| return () => { | |
| console.log('hi'); | |
| }; | |
| }; | |
| fetchData(); | |
| }, []); | |
| return ( | |
| <> | |
| <Button>Refresh</Button> | |
| {console.log('data', data)} | |
| <Table numRows={5}> | |
| <Column name="Test" cellRenderer={cellRenderer(data)} /> | |
| <Column /> | |
| <Column /> | |
| </Table> | |
| </> | |
| ); | |
| } | |
| interface User { | |
| id: string; | |
| name: string; | |
| } | |
| export default MyTable; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment