Search code examples
firebasereact-nativeredux-firestore

Why react native map function is not working properly?


I am trying to retrieve data from firebase firestore. Data from the firestore is logging on the console but not displaying when I use component.

renderList = () => {
        const { accounts } = this.props
        accounts && accounts.map((account) => {
            return (
                <View>
                    <Text>{account.accountName}</Text>
                    {console.log(account.accountName)}
                </View>
            )
        })
    }

    render() {
        return (
            <>
                {this.renderList()}
            </>
        )
    }

In the above coding console.log(account.accountName) is working but it is not printing in the render method. I need to create a list with that data.


Solution

  • Try this please :

        renderList = () => {
                const { accounts } = this.props;
         if(accounts){
                return accounts.map((account) => {
                    return (
                        <View>
                            <Text>{account.accountName}</Text>
                            {console.log(account.accountName)}
                        </View>
                    )
                })
    }
            }
    
            render() {
                return (
                    <>
                        {this.renderList()}
                    </>
                )
            }
    

    hope it helps