Created
April 25, 2018 02:33
-
-
Save antonderegt/94818f8400e6890f8069d34dbb39e675 to your computer and use it in GitHub Desktop.
Step 4: Connect to FIrebase /src/App.js
This file contains 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, { Component } from 'react'; | |
import ReactTable from 'react-table' | |
import 'react-table/react-table.css' | |
import firebase from './config' | |
class App extends Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
users: [] | |
} | |
} | |
componentWillMount(){ | |
this.getUsers() | |
} | |
getUsers() { | |
let users = [] | |
firebase.database().ref(`users/`).once('value', snapshot => { | |
snapshot.forEach(snap => { | |
users.push(snap.val()) | |
}) | |
this.setState({ | |
users | |
}) | |
}) | |
} | |
render() { | |
const userColumns = [ | |
{ | |
Header: "Name", | |
columns: [ | |
{ | |
Header: "First Name", | |
id: "firstname", | |
accessor: d => d.firstname | |
}, | |
{ | |
Header: "Last Name", | |
id: "lastname", | |
accessor: d => d.lastname | |
} | |
] | |
}, | |
{ | |
Header: "Age", | |
columns: [ | |
{ | |
Header: "Age", | |
id: "age", | |
accessor: d => d.age | |
} | |
] | |
} | |
] | |
return ( | |
<div style={style}> | |
<div> | |
<h1>Export Demo</h1> | |
<button>Export to Excel</button> | |
<ReactTable | |
style={{marginLeft:'-40%', marginRight:'-40%'}} | |
data={this.state.users} | |
columns={userColumns} | |
/> | |
</div> | |
</div> | |
); | |
} | |
} | |
const style = { | |
display: 'flex', | |
justifyContent: 'center', | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment