Home > other >  React Typescript: Ant Design Alert not rendering
React Typescript: Ant Design Alert not rendering

Time:12-31

I have an Array messages and try to render different Alert if the Status is true but it dont render in the Browser. Console.log(message) has shown that the message is not empty.

return (
   <Space direction="vertical" >
      {messages.map(item => {
         item.status ?
            <Alert
               message={item.title}
               description={item.statusMessage}
               type="success"
               showIcon
            /> :
            <Alert
               message={item.title}
               description={item.statusMessage}
               type="error"
               showIcon
            />
      })}
   </Space>
);

CodePudding user response:

Please bear in mind that this map() function will not return anything, because its content is in curly brackets {} and not parentheses (). You could also use return item.status ? ....

  • Related