0
Follow
2
View

The array doesnt print its values in React

donkey18 注册会员
6 days ago

modify your renderChat function to use map instead and the console log message should be before the return statement of the map function

const renderChat = () => {
    return (
        chat.map(msg => {
            console.log(msg.data)
            return (
                

{msg.data["message"]}

) }) ) }
dhl7777 注册会员
6 days ago

Please use map instead of forEach

    const renderChat = () => {
    return (
      chat.map(msg => {
        

{msg.data["message"]}

console.log(msg.data) }) ) }
zhh1127 注册会员
6 days ago

Use map instead of forEach

map actually returns an array of the returned results.

forEach on the other hand does not return anything.

const renderChat = () => {
    return (
      chat.map(msg => {
        console.log(msg.data);
        return 

{msg.data["message"]}

; }) ) }