I have a user db in Firebase that uses the unique user id as the Key and within that key/value pairs like name: 'jane doe', email: '[email protected]', etc. What I want to do is map the object and get the key values within. I'm able to get the Key (user id), but not the object key value pairs. Here's my code:
export default class Home extends Component { constructor(props) { super(props); var users = {}; this.state = { users }; } componentDidMount() { const dbRoot = firebaseDb.database().ref().child('users'); dbRoot.on('value', snap => { const dbUsers = snap.val(); this.setState({ users: dbUsers }); }); } render() { return ( <div> <div> {Object.keys(this.state.users).map(function(user, i) { return <div key={i}>Key: {user}, Value: {user.name}</div>; })} </div> </div>); } } user.name comes back undefined. I've tried using this.state.users.name but I get a "state is undefined" message. Can someone point me in the right direction. Thanks!