【发布时间】:2018-01-27 15:07:23
【问题描述】:
const ChatBox = ({ messages, sendInput }) => {
<Card fluid className={theme} raised style={{ height: '100%' }}>
<ChatLog
messages={messages}
/>
<RecordInput // has internal recording state
sendInput={sendInput}
/>
</Card>
}
我的ChatBox 包含ChatLog 和RecordInput。
ChatLog 包含要显示的消息列表。
RecordInput 是要发送到ChatLog 的用户录音输入。该组件有一个内部recording 状态,可以是true 或false。
我想将此recording 状态发送到作为兄弟组件的ChatLog。
一种解决方案:我可以将ChatBox 设为具有recording 状态的类组件并将其传递给ChatLog 和RecordInput .. 但我宁愿不重构我的无功能无状态组件..
还有其他方法可以做到这一点吗?也许是 redux 或进行某种克隆?
【问题讨论】:
标签: javascript reactjs components state