【发布时间】:2020-01-31 02:14:55
【问题描述】:
您好,我有以下逻辑来制作一个简单的聊天机器人,但由于某种原因我无法显示消息:
const ChatBot = () => {
return (
<Styled.ChatBox>
<ChatMessage bot={true}>Hi.</ChatMessage>
<ChatMessage bot={false}>Hello.</ChatMessage>
</Styled.ChatBox>
);
};
这是我的聊天机器人:
function ChatMessage(props) {
return (
<Styled.ChatMessage bot={props.bot}>{props.children}</Styled.ChatMessage>
);
}
ChatMessage.defaultProps = {
bot: false,
};
const Chat = props => {
console.log(props.children);
return (
<Styled.ChatBox>
<Styled.ChatHeader />
<Styled.ChatLog>{props.children}</Styled.ChatLog>
<Styled.ChatInput>
<textarea placeholder="aaaaa ..." rows={4} />
<button>Send</button>
</Styled.ChatInput>
</Styled.ChatBox>
);
};
我真的无法确定我做错了什么 我不知道我是否以最好的方式或最好的逻辑做到了 我有一个用样式化的 comp 制作的 div 这将是根据道具机器人显示消息的位置 我会收到消息,但由于某种原因我无法显示消息。 示例: https://codesandbox.io/s/eager-torvalds-fyi77
【问题讨论】:
标签: reactjs